In Rails, can we .present? check if there is a nil line and contains something other than a space or an empty line:
"".present? # => false " ".present? # => false nil.present? # => false "hello".present? # => true
I would like for similar functionality in Javascript, without having to write a function for it, like function string_present?(str) { ... }
Can I do something with Javascript out of the box, or by adding a String prototype?
I have done this:
String.prototype.present = function() { if(this.length > 0) { return this; } return null; }
But how would I do this work:
var x = null; x.present var y; y.present
Zabba source share