高级程序设计里面的写法是下面这样的
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;
}
}那么我像下面这样写是不是一样的,区别只在于他们的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;
}
}
Cats萌萌
随时随地看视频慕课网APP
相关分类