官术网_书友最值得收藏!

What happened to all the classes?

The second edition of this book contained quite a number of examples using the class feature that is new in ES2015. The revised examples in this edition use factory functions instead, and the class keyword never appears. Why is this, exactly?

ES2015 classes are essentially just syntactic sugaring for factory functions. By this I mean that they ultimately transpile down to factory functions anyway. Although classes can provide a certain level of organization to a complex piece of code, they ultimately hide what is going on underneath it all. Not only that, using OO paradigms, such as classes, is effectively avoiding one of the most powerful and elegant aspects of JavaScript as a language, which is its focus on first-class functions and objects. Your code will be simpler and more elegant using functional paradigms than OO, and you'll find it less difficult to read examples in the D3 community, which almost never use classes.

There are many, much more comprehensive arguments against using classes than I'm able to make here. For one of the best, refer to Eric Elliott's excellent The Two Pillars of JavaScript pieces at:
 www.medium.com/javascript-scene/the-two-pillars-of-javascript-ee6f3281e7f3.

主站蜘蛛池模板: 弥勒县| 贵港市| 勐海县| 聂荣县| 秭归县| 玉田县| 柘城县| 科技| 苍溪县| 新密市| 阿尔山市| 永昌县| 宜黄县| 西和县| 竹溪县| 河西区| 陈巴尔虎旗| 达尔| 宁武县| 岳阳县| 道孚县| 香河县| 舟山市| 随州市| 黑水县| 灵台县| 康保县| 淮安市| 宜黄县| 繁昌县| 随州市| 蒙阴县| 本溪市| 莱芜市| 孟津县| 闵行区| 齐齐哈尔市| 通城县| 松江区| 奇台县| 江油市|