// 维数组// function fn() {// console.log(arguments)// }// fn(10,20,30,40)// 伪数组转真数组var arr = {0 :’王亚浩’,1 : ’23’,length : 2}var arr1 = Array.prototype.slice.call(arr)console.log(arr1)arr1.push(‘张飞’,’张云’)console.log(arr1)
关于call 的用法 可以调用函数,可以改变函数this的指向
call(‘参数一’,’参数二’)
参数一 : 悲改变的this指向参数一 , 参数二 是函数的实参
function num() {
console.log(111)
console.log(this.name) //王亚浩
}
function person(){
var obj = {
‘name’ : ‘王亚浩’
}
return obj
}
num.call(person())
伪数组与数组:
在数组中数值型的下标 给对象添加数据,不能使用点
让维数组借用数组的方法 push() push()方法存在对象的原型上
Array.protoType.push.call(‘{}’)
call是用来改变this的指向的
[] 如果空数组开头 空数组前面一定要加个分号
使用call的场景,借用方法 。借用思路
1、有什么方法已经实现了这个功能
2、去借用他的方法
3、拿到这个方法
转载请注明:前端Tree » 关于call()方法的一个简单说明和用法