using prototype method we can create new methods… like…
Object.prototype.newMethod=function(){
// do something
}
Here I am defining the newMethod with an anonymous function… now if I want to use this method, I have to use it like: <object>.newMethod();
But now I want to create a new method which I can use like: <object>.newMethod;… no brackets… How can I do that…??
please don’t use any jQuery…
I can’t really understand why you would want to do that, but it is possible, albeit with a nasty hacky workaround. What you’re actually looking for, AFAIK, is a magic property (like the
someArray.lengthproperty).This is just to show you that, yes it is theoretically possible, but please, please, don’t use this kind of overly polluted hacks… I haven’t thoroughly tested this, but ATM, I’ve already noticed that
console.log(foo.length);can return a different value, not sure why, yet: