1、this是指调用此函数的对象
function showCar(){
alert(car.color);//输出对象car的color属性
}
但设计函数的时候不可能都知道对象的名字,于是this的作用就来了。
function showCar(){
alert(this.color);//this是调用此函数的对象
}
car1.showCar();//输出对象car1的color属性
car2.showCar();//输出对象car2的color属性
1、this是指调用此函数的对象
function showCar(){
alert(car.color);//输出对象car的color属性
}
但设计函数的时候不可能都知道对象的名字,于是this的作用就来了。
function showCar(){
alert(this.color);//this是调用此函数的对象
}
car1.showCar();//输出对象car1的color属性
car2.showCar();//输出对象car2的color属性