변수에 함수를 캐싱하여 코드를 작게하려고했습니다. 예를 들어 :function.call을 변수에 저장할 때 "객체가 함수가 아닙니다"
function test(){
var a = Array.prototype.slice,
b = a.call(arguments);
// Do something
setTimeout(function(){
var c = a.call(arguments);
// Do something else
}, 200);
}
그래서 대신 Array.prototype.slice.call(arguments)
를 호출, 난 그냥 a.call(arguments);
할 수 있습니다.
캐시를 Array.prototype.slice.call
으로 작게 만들려고했으나 작동하지 않았습니다.
function test(){
var a = Array.prototype.slice.call,
b = a(arguments);
// Do something
setTimeout(function(){
var c = a(arguments);
// Do something else
}, 200);
}
이 TypeError: object is not a function
나에게 제공합니다. 왜 그런가요?
typeof Array.prototype.slice.call
은 예상대로 "function"
을 반환합니다.
변수에 .call
을 저장할 수없는 이유는 무엇입니까?
javascript 엔진에서이 오류를 줬습니까? –
가능한 복제본 [Array.prototype.slice.call()을 어떻게 참조할까요?] (http://stackoverflow.com/questions/6835315/how-do-you-reference-array-prototype-slice-call) – pimvdb
@DanD .: Chrome 16. –