0
点赞
收藏
分享

微信扫一扫

ES6的面向对象写法


这是之前的写法

function Previous (name,age){
this.name = name;
this.age = age;
}
let Bin = new Previous('Bin',21);

这是es6的写法

class Person {
constructor(name,age){
this.name = name;
this.age = age;
}
}
let Hongbin = new Person('Hongbin',21);

打印两种写法的实例:

ES6的面向对象写法_面向对象


相比起来更加方便,像真正的面向对象的语言了,为不断进步的js而喝彩,期待JavaScript走的更高更远,加油


举报

相关推荐

0 条评论