技术控

    今日:83| 主题:57824
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] ES6 Features That Can’t Be Ignored (part 1)

[复制链接]
時光已泛黃 投递于 2016-10-17 10:04:51
260 6
Now that we have some great starter projects for Angular 2 and React, it’s easy to hit the ground running with ES6 .
   I summed up the features that will change the way JavaScript Developers code. You can get a full Angular 2 environmenthereor you can go to  es6fiddle or  babeljs to test it online.
  Let’s get started!
   Constants that are inconstant

   Since JavaScript is Object Oriented, when you see ‘constant’ , you can think that your object is going to stay the same forever.
  Well not really.
   This only concern the primitive, if you want to make an object immutable, you need to use  Object.freeze  , example:
   You can’t be half a gangster

  When ES6 get’s high, we go low.
  – Matthieu Drula
   Do you like CoffeeScript ? Well they tried to get some inspiration there.
  What most likely went through their mind:
  “Guys, we might as well put some CoffeeScript like syntax in it since it’s very compact and readable. We will not use curly brackets anymore”.
   

ES6 Features That Can’t Be Ignored (part 1)

ES6 Features That Can’t Be Ignored (part 1)-1-技术控-forever,features,running,example,started

   

ES6 Features That Can’t Be Ignored (part 1)

ES6 Features That Can’t Be Ignored (part 1)-2-技术控-forever,features,running,example,started

  “Ahhh nevermind I already miss those lovely brackets, let’s put them back.”:
   All this fumble because of implicit return . If you only have  one  line of code, you can skip the brackets since the returned value can only be the result of this line, if not, you need to add them.
  So. Quick test.
  1.  Almost CoffeeScript (ES6):
  2. CoffeeScript:
  Which one do you want to bring to prom night? (Hint: Number 2).
   The very useful ones

   The spread operator

   This feature might be very useful if you are working with Angular 2 and the change detection doesn’t kick in when you update an array.
   This operator is a quick way to realise a concatenation or splitting a string :
   Multiline strings and variable interpretation

   ES6 finally brought something that has been present for years in other languages and was dreadfully missing in JavaScript. By using the backquote symbol, you can break lines and indent your strings. You can also combine that with the use of ${} in order to use some variables.
   Export/Import   

  It’s something that you must have encountered if you have read other articles about Angular 2.
  Here is an example:
   Property Shorthand

  This one is by far my favourite.
  Before:
  Now with ES6:
   Combined with the new Function Signature feature it gets more powerful !
   Function Signature

  We can now assign the parameters of a function:
  
       
  • By default ex: doSomething(a=1, b=2)   
  • By destructuring:  
  
       
  • By changing the arguments names ex:  f({a: name, b: age})   
  • Or by selecting them with a shorthand ex: f({name, age})  
  So now we can do cool things like:
   The controversial one

   Do you like JAVA ? Well ES6 is now JAVA. Period. Next.
  Joke aside.
  There are many features that have been
    stolen   implemented from JAVA. The most obvious ones:
  Classes:
  Inheritance:
   Eric Elliott said about classes that they are “the marauding invasive species” you can (must) have a look at his well-described article here .
   If you are ready to fight for your own style, prepare to receive friendly-fire from many of your Angular 2 colleagues.

ES6 Features That Can’t Be Ignored (part 1)

ES6 Features That Can’t Be Ignored (part 1)-3-技术控-forever,features,running,example,started

   Conclusion

  ES6 comes with new features that make JavaScript looks like a different language.
   Some features are really easy to use like the multi line strings . Others will however require a little bit of time to master like the use of constants .
   The next post will be about async , promises , symbols , destructuring assignment and many other features.



上一篇:产品级微服务的八大原则
下一篇:Weex学习与实践(三):iOS原理篇
1594685558 投递于 2016-10-19 02:13:08
林子大了,什么鸟都有了啊!
回复 支持 反对

使用道具 举报

我很无趣 投递于 2016-10-23 04:16:04
我要做个下载软件,名字叫掩耳。因为迅雷不及掩耳。
回复 支持 反对

使用道具 举报

映冬 投递于 2016-10-24 14:43:27
垃圾内容,路过为证。
回复 支持 反对

使用道具 举报

代柔 投递于 2016-11-2 15:52:09
前排,哇咔咔
回复 支持 反对

使用道具 举报

dcqwqd 投递于 2016-11-11 20:14:10
人生的两大悲剧:一是万念俱灰,一是踌躇满志。
回复 支持 反对

使用道具 举报

我眨眨亮瞎你 投递于 2016-11-20 15:55:35
一脸的虚假繁荣。
回复 支持 反对

使用道具 举报

我要投稿

推荐阅读


回页顶回复上一篇下一篇回列表
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 | 粤公网安备 44010402000842号 )

© 2001-2017 Comsenz Inc.

返回顶部 返回列表