关于Array.prototype.slice.call(arguments,0)的理解
来源:互联网 发布:贝叶斯优化算法 编辑:程序博客网 时间:2024/06/05 00:26
最近在学js,第一眼看这个看不懂啊,于是搜了搜,理解如下:
问题 :var args = Array.prototype.slice.call(arguments,2),里的Array.prototype.slice.call(arguments,2)是什么意思?书上讲的很苍白,无法理解
首先 这是创建了一个类数组arguments(就是没有具体数据的数组),使用Array.prototype把类数组转换为原型数组,prototype是原型的意思
为什么要转换为原型数组呢?因为类数组是没有slice()方法的,需要把类数组转换为原型数组才能调用slice()这个方法
然后 解释 slice()和call()方法
slice() 方法可从已有的数组中返回选定的元素。 语法 arrayObject.slice(start,end),在本句中的意思是要去遍历数组
call() 方法定义:调用一个对象的方法,以另一个对象替换当前对象,在这里的意思大概就是调用原型数组的方法,用原型数组代替当前对象(类数组),所以args数组就完全变成真正的数组啦!
阅读全文
0 0
- 关于Array.prototype.slice.call(arguments,0)的理解
- Array.prototype.slice.call(arguments,0)
- Array.prototype.slice.call(arguments,0)
- JS 有趣的应用 : Array.prototype.slice.call(arguments,0)
- JS 有趣的应用 :Array.prototype.slice.call(arguments,0)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- cron服务
- Linux基础知识笔记(一)
- 推荐系统中基于深度学习的混合协同过滤模型
- ViewPager自动轮播+GridView展示+缓存到id
- Spark1.4中DataFrame功能加强,新增科学和数学函数
- 关于Array.prototype.slice.call(arguments,0)的理解
- 利用time.h获取本地时间
- Unity 判断目标分辨率是16比9还是16比10
- Android任务栈的完全解析
- 不让scrollerView里的editext 不自动软键盘,软键盘弹起不顶起底部控件,不遮挡editview
- json格式化后的日期转换为DateTime
- Java简介—动力节点Java学院
- 多线程之其他
- UVALive