Douglas Crockford在JavaScript中使用Class Free OOP

道格拉斯·克罗克福德(Douglas Crockford)在ES6的“更好的部分”(The Better Parts)上做了非常好的演讲 除此之外,他鼓励摆脱原型inheritance,转而采用免class级的面向对象方式 。

在这里,他说他停止使用newObject.create ,而this ,但没有真正解释一个替代scheme。 任何人都可以填写我可能看起来如何?

你应该看整个video,他在后面的video中解释。

 function constructor(spec) { let {member} = spec, {other} = other_constructor(spec), method = function () { // accesses member, other, method, spec }; return Object.freeze({ method, other }); } 

这是显示模块模式返回一个冻结的对象 。