看到博客在讲述,发现几种中法,很纠结,你常用那种?
function person(){
this.name = "joker";
}
person.prototype.say = function(){
console.log(this.name);
}
// ------ 第一种
function man(){
}
man.prototype = new person();
// ------ 第二种
function man(){
person.apply(this);
}
// ------ 第三种
var temp = function() {
}
temp.prototype = person.prototype;
function man(){
}
man.prototype = new temp();
1. 第一种: 常用,属性、原型,都可以用到,貌似木有啥问题。。。。还是有
2. 明确的是,第二种不能继承原型。
3. 默认没有属性....