Tôi đã cố gắng làm cho mã của mình nhỏ hơn bằng cách lưu vào bộ nhớ các hàm. Ví dụ:"đối tượng không phải là một hàm" khi lưu hàm.call thành một biến
function test(){
var a = Array.prototype.slice,
b = a.call(arguments);
// Do something
setTimeout(function(){
var c = a.call(arguments);
// Do something else
}, 200);
}
Vì vậy, thay vì gọi Array.prototype.slice.call(arguments)
, tôi chỉ có thể làm a.call(arguments);
.
Tôi đã cố gắng làm cho điều này thậm chí nhỏ hơn bằng cách lưu vào bộ nhớ cache Array.prototype.slice.call
, nhưng điều đó không hoạt động.
function test(){
var a = Array.prototype.slice.call,
b = a(arguments);
// Do something
setTimeout(function(){
var c = a(arguments);
// Do something else
}, 200);
}
Điều này cho tôi TypeError: object is not a function
. Tại sao vậy?
typeof Array.prototype.slice.call
trả về "function"
, như mong đợi.
Tại sao tôi không thể lưu .call
vào một biến (và sau đó gọi nó)?
công cụ javascript nào đã cho bạn lỗi này? –
có thể trùng lặp của [Làm thế nào để bạn tham khảo Array.prototype.slice.call()?] (Http://stackoverflow.com/questions/6835315/how-do-you-reference-array-prototype-slice-call) – pimvdb
@DanD .: Chrome 16. –