这有什么区别:
function Hero(options) {
options = options || {}
this.nickname = options.nickname || 'Default 1';
this.hp = options.hp || '50'
}
Hero.prototype.walk = function() {
console.log('Hero walked');
}
和这个:
function Hero(options) {
options = options || {}
this.nickname = options.nickname || 'Default 1';
this.hp = options.hp || '50'
this.walk = function() {
console.log('Hero walked')
}
}
使用有什么明显的收获prototype
吗?