The function can be extended as follows
Function.prototype.bind = function(obj) {
var _this = this;
return function() {
_this.apply(obj,arguments);
}
}
The usage is as follows
var a = function(){
alert(this.title)
}.bind(document);
a();
is commonly used here
function myalert() {
this.title = 'hello world';
this.init = function() {
$("#xxx").click(this.close.bind(this));
}
this.close = function() {
alert(this.title)
}
}
var a = new myalert();
a.init();