ES5 vs ES6 ( With example code )
ES5 vs ES6 ( With example code )
型号:
价格:
颜色:
浏览:64
数量:
 
I have just launched ProgrammerJournal.com. A standalone blog where I write about Javascript, Web de
I have just launched ProgrammerJournal.com. A standalone blog where I write about Javascript, Web development and software development.
Reducing code with Arrow Function
Arrow functions brought a lot of clarity & code reduction to Javascript. Let’s take a look at different ways we can define function now.
Here is the ES5 version
function greetings (name) {
 return 'hello ' + name
}
Now take a look at different ways we can define function in ES6
const greetings = (name) => {
 return `hello ${name}`;
}
You can see the difference we don’t have to use the function keyword to define the function now but that’s now a big improvement right ?
Have a look at another way we can define a function in ES6
const greetings = name => `hello ${name}`;
This is some code reduction we are talking about earlier. In ES6 if your function has a single parameter then you can altogether ditch the parenthesis around the parameter.
Another thing to notice that we don’t have to write the return keyword to return the computed value, in ES6 if you don’t write function body inside braces the computed expression automatically get returned when the function will be executed.
Manipulating objects in ES6 vs ES5
Objects get a major overhaul in ES6. Things like object destructuring and rest/spread operators made it working with objects very easy now. Let’s jump to the code and try to merge two objects in ES5.
var obj1 = { a: 1, b: 2 }
var obj2 = { a: 2, c: 3, d: 4}
var obj3 = Object.assign(obj1, obj2)
We have to merge the object using Object.assign() which takes both objects as input and outputs the merged object. Let’s take a look how we can tackle this problem in ES6.
const obj1 = { a: 1, b: 2 }
const obj2 = { a: 2, c: 3, d: 4}
const obj3 = {...obj1, ...obj2}
Simple isn’t it ? The spread operator makes merging objects a breeze for the developer.
Let’s take a look at object destructuring now. If you have to extract multiple values from ES5 you have to write 3–4 lines of code like this:
var obj1 = { a: 1, b: 2, c: 3, d: 4 }
var a = obj1.a
var b = obj1.b
var c = obj1.c
var d = obj1.d
Time consuming
以下是网友对 ES5 vs ES6 ( With example code ) 的评论:
发表评论
大名:

版权所有 © a片免费成人毛片免费观看-国产一级片 蜀ICP备123456

这时外面响起来叫门声:”有没有人啊?开门啊!a片免费成人毛片免费观看-国产一级片”白洁一听低声的告诉高义:”是楼上的。”两人才放下心来。高义把慢慢的抽动着,白洁轻轻的扭动着屁股。 叫了几声门,那人嘴里嘟囔着走了,“快a片免费成人毛片免费观看-国产一级片点吧……他快回来了……”白洁喘息着说。高义开始不停地快速抽送,两人交合摩擦的水声“叭叽、叭叽”的响着,“嗯……哼……哦……”白洁轻声的叫着。 很快,高义一泄如注,白洁跪在沙发上喘息了一会儿,a片免费成人毛片免费观看-国产一级片起来刚要穿内裤,便听见门口响起熟悉的脚步声,王申回来了。情急之下,白洁把内裤a片免费成人毛片免费观看-国产一级片塞到了沙发后面,整理了一下衣服,正襟危坐在那里。 高义一看四周也没有人,一下抱起白洁,钻进了旁边一个茂密的小树林…… 茂密的灌木里面有着一片小小a片免费成人毛片免费观看-国产一级片的空地,有意思的是还铺着两张报纸,可惜已经破烂不堪了,在角落的地方竟然还有一个用过的避孕套,里面还有着干涸的。 进了这里,高义的手就已经在白洁的a片免费成人毛片免费观看-国产一级片胸脯上乱摸了,白洁微微喘着气:“别摸脏了,别……”高义就解开她的衬衫扣子,把一对肉鼓鼓的从乳罩上边掏了出来。高义的手很大,但刚好是握住还握不住的感觉,黄豆粒一样大的粉a片免费成人毛片免费观看-国产一级片嫩粉嫩的正在慢慢变硬,秀美的眼睛微微闭着,长长的睫毛在不停地抖动。 高义的手在往上卷着白洁的裙子,可是牛仔裙a片免费成人毛片免费观看-国产一级片很紧,卷不上来,白洁推开高义,手伸到裙子后面,原来后面有一个拉链。拉开拉链,高义把白洁的裙子拉到了脚下,白洁里面是一条水绿色的小内裤,除了三角区之外都是镂空的。高义的a片免费成人毛片免费观看-国产一级片手抚摸着两瓣露出的雪白屁股,让白洁弯下腰,手扶着前面的一个树杈,他解开了裤子……