함수의 싱글 톤 버전을 반환하기 위해 함수 프로토 타입을 확장하려고합니다.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;
}
}
콘솔은 창 개체를 기록합니다. 왜 이것입니다! = 현재 기능입니까? 어떻게 해결할 수 있을까요?
해피 코드 워 : – Florent