高級程序設(shè)計里面的寫法是下面這樣的function Person(name,age,job){ this.name = name; this.age = age; this.job = job; this.lessons = ['Math','Physics'];
}
Person.prototype = { constructor: Person,
getName: function(){ return this.name;
}
}那么我像下面這樣寫是不是一樣的,區(qū)別只在于他們的constructor不一樣?function Person(name,age,job){ this.name = name; this.age = age; this.job = job; this.lessons = ['Math','Physics'];
Person.prototype.getName = function(){ return this.name;
}
}
關(guān)于js中組合使用構(gòu)造函數(shù)模式和原型模式的寫法
Cats萌萌
2018-11-14 13:13:49