It is more a sanity test than anything else. I found that when working with closure in Javascript, I often use the following template to access the enclosing class from within the function:
MyClass.prototype.delayed_foo = function() {
var self = this;
setTimeout(function() {
self.foo();
}, 1000);
};
Obviously, this works fine, and it’s not even a big problem with the job. There is only this little itch in the back of my brain that says, "You do it too hard, mannequin!" Is this a common pattern?
source
share