I am seeing following line of code from source code of grunt npm module –
String.prototype.__defineGetter__(method, function() { return this; });
Just trying to anticipate what will be the value of ‘this’ inside the anonymous function above –
- It points back to ‘method’
- Global ‘window’ object if running in browser or something similar in grunt’s perspective
- Something else depending on the definition of defineGetter if call or apply are used inside the ‘defineGetter’ definition.
Thanks for the help !!
thiswill be the object on which the get operation occurs, which I think will always be the object on which you called__defineGetter__(since I can’t immediately see a way to transfer that function elsewhere, but I wouldn’t guarantee you couldn’t; you’d have to do it on purpose, though).It’s worth noting that
__defineGetter__is non-standard and obsolete. The current way to define a getter is to useObject.definePropertyorObject.defineProperties, like this:…which logs
"HI THERE".Live Example | Source