JavaScript Binding
Its important to always remember that methods are just functions that are default-bound to a certain context:
var Person = function (name) {
this.name = name;
};
Person.prototype = {
getName: function () {
return this.name;
}
};
So each has its own default version of getName
:
var kate = new Person('kate');
kate.getName(); // kate
var john = new Person('john');
john.getName(); // john
Which doesn’t really matter so much:
kate.getName.bind(john)(); // john