Function.prototype.bind = function (oThis) {
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis || window,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
var person = {
age:10,
getAge:function(){
return this.age;
}
}
//
var boundGetAge = person.getAge.bind(person);
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
这里问什么要把这个返回出来的函数原型指向先前对象里面getAge的原型呢?
有大大说是EMCA262标准、、还有人说是断开引用。
求解
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货