道格拉斯克罗克福德在Class免费的OOP在JavaScript [英] Douglas Crockford on Class Free OOP in JavaScript

查看:114
本文介绍了道格拉斯克罗克福德在Class免费的OOP在JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

道格拉斯·克罗克福德(Douglas Crockford)在ES6的更好的部分上做了很好的演讲。除此之外,他鼓励远离原型继承,支持免费的OOP



在这里他说他停止使用新的 Object.create 这个,但没有真正解释一个替代方案。有人可以填写我的看法吗?

解决方案

你应该看整个视频,他在后期的视频

 函数构造函数(spec){
let {member} = spec,
{other} = other_constructor(spec),
method = function {
//访问成员,其他,方法,规范
};

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

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


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.

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
  });
}

It's the revealing module pattern returning a frozen object.

这篇关于道格拉斯克罗克福德在Class免费的OOP在JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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