I wish to extend the String class and add a simple method:
String.prototype.world = function(){
return " world";
}
and I want to do something like:
"hello".world
and get back "hello world". instead of doing:
"hello".world()
calling a function without brackets will return the function object.
What I’m looking for is to execute the function instead of returning it (without specifying the brackets).
Can I do it somehow in JavaScript?
EDIT: according to this, using __defineGetter__ is non standard and deprecated. looking for alternativs.
You can do that using setter getter. jsfiddle. but setter getter are not supported by IE < 9;