変数を関数にキャッシングすることでコードを小さくしようとしていました。たとえば: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. –