es5 组合使用构造函数+原型模式 function Person(name,age){ this.name=name; this.age=age; }
Person.prototype.say=function(val){ console.log(this.name+val); }
var p=new Person('张三',25); p.say("我会八。") //张三我会卦。
es6使用Class类实现
class Person{ constructor(name,age){ this.name=name; this.age=age; } say(val){ console.log(this.name+val) } }
let wuji = new Person("zhangwuji",32); wuji.say("我会九功") //zhangwuji我会九功