function User(name, age){
this.name = name;
this.age = age;
}
User.prototype.greet = function(){
console.log('hi,我是' + this.name + '我现在' + this.age + '岁');
}
this.name = name;
this.age = age;
}
User.prototype.greet = function(){
console.log('hi,我是' + this.name + '我现在' + this.age + '岁');
}
var bb = new User('BB',22);
var bb = new bb.constructor('bb',18); //这行代码和上面的 var bb = new User('BB',22); 这行代码意思是相近的或着说是一样的,
bb.constructor; = console.log(User); 这里的constructor是直接指向User的,所以显示出来的结果是一样的
constructor 这个关键词还有个作用就是复制一个function里面的结构例如:
var dd = new bb.constructor('dd',18);