随笔分类 -  ES6

摘要:Creating Object:Example 1:let name = "Brook";let totalReplies = 249;let avatar = "/users/avatars/brook-user-1.jpg";let user = {name, totalReplies, ava... 阅读全文
posted @ 2016-01-03 16:53 Zhentiw 编辑
摘要:The spread operator allow us to split an Array arguement into individual elements.getRequest("/topics/17/tags", function(data){ let tags = data.tag... 阅读全文
posted @ 2016-01-03 16:32 Zhentiw 编辑
摘要:Problem with the ES5:function displayTags(){ for (let i in arguments) { let tag = arguments[i]; _addToTopic(tag); }}Hard to tell w... 阅读全文
posted @ 2016-01-02 21:47 Zhentiw 编辑
摘要:1. Default Value of function param:The functiondisplayTopicsPreview()raises an error on the very first line when called with no arguments. Let's fix t... 阅读全文
posted @ 2016-01-02 04:59 Zhentiw 编辑
摘要:var parts = ['shoulders', 'knees'];var lyrics = ['head', ...parts, 'and', 'toes']; // ["head", "shoulders", "knees", "and", "toes"]var arr1 = [0, 1, 2... 阅读全文
posted @ 2015-11-27 03:06 Zhentiw 编辑
摘要:Array.from()lets you convert an "iterable" object (AKA anarray-likeobject) to an array. In this lesson, we go over grabbing DOM nodes and turing them ... 阅读全文
posted @ 2015-11-22 23:04 Zhentiw 编辑
摘要:Convenient method to find one item in an array, avoid writing and for + if:let arys = [1,,5,,6] ;let target = 6;let res = arys.find(item => item === t... 阅读全文
posted @ 2015-11-12 03:23 Zhentiw 编辑
摘要:In es5, you can use indexOf to get the index of one item in an array.In es6, you can use findIndex(), which is more prowful:[NaN].indexOf(NaN) // -1[N... 阅读全文
posted @ 2015-11-12 03:16 Zhentiw 编辑
摘要:ES6 (ES2015) introduces astandardized module formatto Javascript. We'll take a look at the various forms of defining and importing modules. UsingWebpa... 阅读全文
posted @ 2015-08-12 00:18 Zhentiw 编辑
摘要:Rest Parameters:In ES5, when you don't know how many paramters will be passed in, you can use arguments:let sum = function(){ let result = 0; fo... 阅读全文
posted @ 2015-05-01 18:40 Zhentiw 编辑
摘要:'const' keyword is for creating a read only variable, something you can never change once created.'const' likes 'let' keyword alos has block scope.des... 阅读全文
posted @ 2015-04-29 04:14 Zhentiw 编辑
摘要:ES-Next:Esnext is similar to traceur, you can use command line to compile files.Install:npm install esnext -g Here's how to compile a single file an p... 阅读全文
posted @ 2015-04-29 03:47 Zhentiw 编辑
摘要:Polyfill is something you don't need to set up traceur but start to use es6 in today's browser.You can search for polyfill which you want to use on Go... 阅读全文
posted @ 2015-04-29 03:24 Zhentiw 编辑
摘要:In ES5, we have for ... in:var phones = ["iPhone", "Nexus", "Nokia"];for(i in phones){ console.log(phones[i]);}//iPhone//Nexus//NokiaWhat we get fr... 阅读全文
posted @ 2015-01-02 05:44 Zhentiw 编辑
摘要:ES6 provides Map, it is a set of k-v pair. Key can be number, string, object, function and even undefined.var m = new Map();Methods:1. set(k,v)m.set("... 阅读全文
posted @ 2015-01-02 05:43 Zhentiw 编辑
摘要:Es6 provides "Set", it likes array but the data inside should be unqiue."Set" is a construct function, you should call:var s = new Set();Methods:1.add... 阅读全文
posted @ 2015-01-02 05:35 Zhentiw 编辑
摘要:Define object:var color = "blue";var speed = 120;var car = {color, speed};console.log(car.color); // blueconsole.log(car.speed); // 120in ES5:var ca... 阅读全文
posted @ 2015-01-01 22:10 Zhentiw 编辑
摘要:Using for..of statement:function* greeting(){ console.log(`Generators are "lazy"`); yield "How"; console.log(`I'm not called until the second... 阅读全文
posted @ 2014-11-23 21:37 Zhentiw 编辑
摘要:Generators in ECMAscript 6 are first-class coroutines that produce encapsulated suspended execution(暂停执行) contexts.Yield values and iterate over them ... 阅读全文
posted @ 2014-11-23 21:05 Zhentiw 编辑
摘要:The spread operator (...) allows you to "explode" an array into its individual elements.Spreate an array:console.log([1,2,3]); // [1, 2, 3] conso... 阅读全文
posted @ 2014-11-23 01:41 Zhentiw 编辑

点击右上角即可分享
微信分享提示