ecmascript 的一些发展新动向



========== ecmascript 的一些发展新动向 (e5a57b27 - initial commit)

更弱、更受限
    严格模式禁止 arguments.callee - 可以 "让 js 引擎简化调用堆栈"
    - "Are you saying it is depricated just because it's hard to optimize? That's kinda silly."
    - http://stackoverflow.com/questions/103598/why-was-the-arguments-callee-caller-property-deprecated-in-javascript
    - 我认为 arguments.callee 是很重要的元信息
    Function.prototype.bind - 虽然 c++ 到处都是毛病,但绑定可比 js 的这个强多了,所幸 js 自己写绑定比 c++ 简单得多

更扭曲、更麻烦
    (肥)箭头函数
    - 名字恶心 - 肥箭头 - 恶心的不是肥字,是为什么要加个肥字,或者说为什么等号和连字号相比是肥
    - - 或许和把自己的宝贝命名为狗剩是同一种思路?这在某种意义上的确可笑
    - 语法恶心 - () => {} ,当参数个数 = 1 时可省略圆括号;当语句个数 = 1 时可省略花括号,此时隐含 return 前缀
    - 在定义(而不是调用)时绑定 this - 可能是好的初衷,但绝对是另一个混乱的根源
    - 不能作为构造函数 - 因为其 this 在定义处就绑定了
    - 没有 arguments - 莫名其妙,参见另一个让人哭笑不得的 es7 提案 additional meta properties
    let, const
    - "让 js 引擎使用更少内存",let 排除作用域外引用,const 只分配一次 - 我觉得这是引擎的任务 
    - "const 防止无意间修改变量" - 无意间修改变量显然是程序 bug
    - 我的看法是 const 比 let 强点,用来定义全局变量。回忆 js 的值和引用,const 能锁定几个?
    promise - 必须用 new,必须传入闭包 - js 闭包是很好,可你要求我使用闭包?大家可以看看 fetch,感受一下爽不爽

更不像 js
    let, const, class - "the determined Real Programmer can write Fortran programs in any language"
    - 经过这么多语言的 let 的轮番攻击现在我看见 let 就反胃,本来 let 是个很好的词。这让我越发喜欢 var
    public static void main - "soon brother, soon"

更喜感
    `   - 模板字符串
    @   - 装饰 https://github.com/wycats/javascript-decorators - 装饰不是我翻译的,是设计模式翻译的
    #   - 私有成员,firefox 似乎以前也用过井号
    ::  - 绑定 - 2 标点不算多,展开运算符有 3 个标点呢。期待 4 标点、5 标点甚至 10 标点组合!
    这些标点一直保留着不让代码用,为的是搬出来自己用,给你一个惊喜

更打脸
    重新定义以前占用的关键字、标点 - 这一点 c++ 已经做了,js 虽然暂时没动静但我确定这些人肯定不甘落后
    arguments - es6 - 严格模式禁用,箭头函数没有;es7 - 把 arguments 换个名字叫 function.xxx 吧
    - https://github.com/allenwb/ESideas/blob/master/ES7MetaProps.md

Q - "You don't _have_ to use feature $x because it is new"
A - 我不知道这句话有什么用,这句话是说 js 中的任何 feature 都没必要用?

Q - "The CONST and LET keywords is not only about performance and memory, it's also about trust!
    It's about that I can trust that noone else screwed up these variables!"
A - "If "someone" adds to Object.prototype, you track it down, remove the offending code, then remove the offending developer."
  - http://stackoverflow.com/questions/7847350/how-to-check-if-object-is-empty
  
https://github.com/tc39/ecma262
http://kangax.github.io/compat-table/es6/
http://kangax.github.io/compat-table/esnext/
http://www.bennadel.com/blog/2949-var-for-life---why-let-and-const-don-t-interest-me-in-javascript.htm

理想语法 - 括号 - 左边 != 右边和左边 = 右边的区别在于前者可嵌套
()      - 表达式?
[]      - 数组
{}      - 对象  
() {}   - 函数
``      - 模板字符串
''      - 字符串
""      - 字符串
//      - 中间有内容时是正则表达式,否则开始单行注释 

理想语法 - 符号、关键字不区分大小写



posted @ 2016-06-05 06:59  see1see  阅读(192)  评论(0编辑  收藏  举报