调用方法和Array.prototype.slice.call的用法
usage of call method and Array.prototype.slice.call
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
我在看绑定函数的来源,我只是在想为什么他们在做一个Array.prototype.slice.call
时,我可以直接做一个切片到我的arguments
。
因为arguments
不是纯JavaScript数组,而是类数组对象。因此,为了对其进行更改,您必须使用Array.prototype.slice.call
将其转换为实际数组。
arguments
对象不是Array。它类似于数组,但是除了length
,没有其他Array属性。
相关文章:
- call()和apply()实际上是用来欺骗方法处理类似数组的对象的
- 原型和用法 Javascript
- 在IntelliJ IDEA中,如何将JS文件从“;查找用法“;使用TypeScript时的结果
- JavaScript中的这个call()-方法是如何工作的
- 限制npm依赖模块's require(隔离)的用法
- Slack Oauth/Authorize API Call
- 引导工具提示用法,在搜索字段中
- 如何对jquery中的未命名函数执行.call()
- Meteor.call()回调未向模板返回值
- 用于添加两个数字的javascript闭包的用法
- Object.prototype.hasOwnProperty.call() vs Object.prototype.h
- 如何将动态构建的字符串作为http头在http.call中与流星一起传递
- Function.prototype.call和Function.protoype.all只应用一个参数
- JavaScript.call()函数“;这个“;值返回3
- IntelXDK Cordova iframe Phone Call
- javascript中不带转义字符串的${variable}用法
- 了解插件代码中$.each内部传递的参数的用法
- Chris Coyer中call()的用法'的自定义事件示例
- Javascript .call() 用法.一个工作案例,一个不是.有什么区别
- 调用方法和Array.prototype.slice.call的用法