function Leo1 (name,age){
this.name=name;
this.age=age;
}
function Leo2(name,age){
Leo1.apply(this,[name,age])
Leo1.call(this,name,age)
//call传参的时候除去第一个是以普通参数的方式去传参
//apply 除去第一个参数外,之后的参数是以数组的方式去传参
}
var Leo2=new Leo2("得肺",17);
console.log(Leo2)
this指向。
1. 在普通函数下 this指向的是 window
function arr(){
console.log(this)
}
arr()
这里弹出的就是window
2.作为方法调用,那么this就是指实例化的对象
3. 对象下 this 指向的是自己本身。
4. 在定时器下 除es6 this 指向window。