我想扩展函数原型来返回函数的单例版本。在Function.prototype中访问“this”不可能?
Function.prototype.once = function() {
var called = false, memo;
return function() {
console.log('AP', this);
if (!called) memo = this.apply(this, arguments);
called = true;
return memo;
}
}
控制台记录窗口对象。这是为什么!=当前功能?以及如何解决这个问题?
快乐codewars :) – Florent 2014-09-29 13:28:38