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

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.

主站蜘蛛池模板: 德阳市| 罗田县| 凤山县| 长海县| 漳平市| 利川市| 安阳县| 正镶白旗| 德惠市| 海宁市| 鹤岗市| 平乡县| 浪卡子县| 元朗区| 澄迈县| 绥宁县| 巴林左旗| 德钦县| 宁明县| 自治县| 建昌县| 东安县| 集贤县| 仪陇县| 阳高县| 龙口市| 盐源县| 吉隆县| 永年县| 金溪县| 安乡县| 广饶县| 云浮市| 万盛区| 江华| 三明市| 淄博市| 克拉玛依市| 宝应县| 武隆县| 绿春县|