区别
传入的参数不同
作用
this指向
let name = '张三'
age = 28
let obj = {
name: '里斯',
myFunction: function () {
console.log(this.name + this.age);
}
}
let db = {
name: '王五',
age: 30
}
obj.myFunction() //李四 undefined
obj.myFunction.call() //call没有参数,this指向全局, 张三 28
obj.myFunction.call(db) //this指向db, 王五 30
继承
function A() {
this.name = 'Kevin'
this.showname = function () {
console.log(this.name);
}
}
function B() {
this.name = 'Kobe'
A.call(this) //this代表B 使B继承A所有的属性和方法
}
let b = new B()
B.showname() //Kevin