prototype的经典使用场景就是为对象增加属性和方法,如给自定义的Man对象增加个姓名属性和语言方法:
function man() { this.age = "22"; } var tom = new man(); man.prototype.name = "tom"; man.prototype.say = function () { alert("english"); }; alert(tom.name); tom.say();结果:弹出”tom”,弹出”english”