Douglas Crockford 谈 JavaScript 中的 Class Free OOP [英] Douglas Crockford on Class Free OOP in JavaScript

查看:11
本文介绍了Douglas Crockford 谈 JavaScript 中的 Class Free OOP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Douglas Crockford 对 ES6 的更好的部分"进行了非常好的演讲.除其他外,他鼓励从原型继承转向无类 OOP.

Douglas Crockford has a really good talk on "The Better Parts" of ES6. Among other things, he encourages a move away from prototypal inheritance in favor of class free OOP.

在这里他说他不再使用 newObject.createthis,但并没有真正解释替代方案.有人能告诉我它的样子吗?

Here he says he stopped using new, Object.create, and this, but didn't really explain an alternative. Could anyone fill me in on how that might look?

推荐答案

你应该观看整个视频,他在 稍后在视频中.

You should watch the whole video, he explains it at later in the video.

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

  return Object.freeze({
      method,
      other
  });
}

这是揭示模块模式返回一个冻结对象.

这篇关于Douglas Crockford 谈 JavaScript 中的 Class Free OOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆