可能重复:
了解JavaScript中的原型继承
好的,所以我对JS中的OOP概念有些新意.
这两个代码片段之间有什么区别:
function animal(){
this.name = 'rover';
this.set_name = function(name){
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
function animal(){
this.name = 'rover';
}
animal.prototype.set_name = function(name){
this.name = name;
}
Run Code Online (Sandbox Code Playgroud)
他们都做同样的事情,那有什么区别?