1、对象方法调用模式 方法内部的this指向当前调用者的对象d
定义类 (构造函数)
function Dog (dogName){
//创建一个空对象 让空对象==this
this.name = dogName;
this.age = 0;
this.run = function(){
console.log(this.name + 'is running...')
}
//如果函数当做构造函数来调用(new)并且没有返回任何数据的时候 默认返回this
}
var d= new Dog('wangwang');
d.run();
2、构造器调用模式 new
function Cat(){
this.name = "cat"
this.age = 19;
this.run = function(){
console.log(this.name + 'is running...')
}
}
var cat = new Cat(); //构造函数调用模式
cat.run() //方法调用模式