Slide 57
Slide 57 text
var bind = function(callback, scope) {
return function() {
var args = Array.prototype.concat.call(arguments);
callback.apply(scope, args);
};
}
var Person = function() {
this.name = "Steve";
};
Person.prototype = {
sayDelayedHello: function(delay) {
setTimeout(bind(this.sayHello, this), delay);
},
sayHello: function() {
alert("Hello, my name is " + this.name);
}
};
var person = new Person();
person.sayDelayedHello(1000);
Alert: "Hello, my name is Steve"