The dark side of Function.prototype.bind
blog.amasad.me
blog.amasad.me
Creates a new function that when called, itself calls
this function in the context of the provided `this` value [1]
In the Editable example, the problem is not even bind()'s fault. Even if you used the original, unbound functions for the events, replacing them later wouldn't change the event handlers... what you'd need to respect the prototype chain is to call the object's method inside the handler: this.$reset.click(function(){
this.reset()
}.bind(this))
//or
var self = this
this.$reset.click(function(){
self.reset()
})
[1] https://developer.mozilla.org/en/JavaScript/Reference/Global... var bind = function (obj, m) {
return function () {
obj[m].apply(obj, Array.prototype.slice.call(arguments));
};
};https://github.com/documentcloud/underscore/blob/master/unde...