I was trying to make my code smaller by caching functions to variables. For example:
function test(){
var a = Array.prototype.slice,
b = a.call(arguments);
// Do something
setTimeout(function(){
var c = a.call(arguments);
// Do something else
}, 200);
}
So instead of calling Array.prototype.slice.call(arguments)
, I can just do a.call(arguments);
.
I was trying to make this even smaller by caching Array.prototype.slice.call
, but that wasn't working.
function test(){
var a = Array.prototype.slice.call,
b = a(arguments);
// Do something
setTimeout(function(){
var c = a(arguments);
// Do something else
}, 200);
}
This gives me TypeError: object is not a function
. Why is that?
typeof Array.prototype.slice.call
returns "function"
, like expected.
Why can't I save .call
to a variable (and then call it)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…