摘要: var obj = { valueOf: function() { return 3; }, toString: function() { return 2; }}; const sym = Symbol(obj);console.log(sym); // 'Symbol(2)' call toSt 阅读全文
posted @ 2017-05-15 11:36 ax=null 阅读(203) 评论(0) 推荐(0)
摘要: function dedupe(arr) { return Array.from(new Set(arr));} var arr = [2,2,3,4,5,4];console.log(dedupe(arr)); // [2, 3, 4, 5] 阅读全文
posted @ 2017-05-15 11:25 ax=null 阅读(116) 评论(0) 推荐(0)
摘要: Array.prototype.clone = function() { return this.slice();} var arr= [1,2, 3];var arr2 = arr.clone();console.log(arr2); // [1, 2, 3] 阅读全文
posted @ 2017-05-11 00:51 ax=null 阅读(120) 评论(0) 推荐(0)
摘要: var arr = [1, 2, 3,[false], ['hello']];var arr2 = [].concat.apply([], arr);console.log(arr2); // [ 1, 2, 3, false, 'hello' ] 阅读全文
posted @ 2017-05-07 16:21 ax=null 阅读(185) 评论(0) 推荐(0)
摘要: var arr = [1, 2]; arr[arr.length] = 3; console.log(arr); // 速度比 push 快 阅读全文
posted @ 2017-05-03 22:53 ax=null 阅读(190) 评论(0) 推荐(0)
摘要: function Employee(name) { this.name = name; this.say = function() { log.add("I am employee " + name); } } function EmployeeFactory() { this.create = function(name) { return new Employee(); ... 阅读全文
posted @ 2017-05-03 21:37 ax=null 阅读(155) 评论(0) 推荐(0)
摘要: var arr = ['a', 'b', 'c']; // 1 for (var index = 0; index < arr.length; index++) { console.log(arr[index]); } // 2 ES5 arr.forEach(function (value) { console.log(value); }); // 3 for-in work the... 阅读全文
posted @ 2017-05-03 21:19 ax=null 阅读(681) 评论(0) 推荐(0)
摘要: var s1 = `string text`; console.log(s1); console.log(typeof(s1)); var s2 =`text line1 text line2`; console.log(s2); // true console.log('\`' === '`'); var a = 1, b = 2; console.log(`sum ... 阅读全文
posted @ 2017-05-03 21:18 ax=null 阅读(135) 评论(0) 推荐(0)
摘要: function* fib() { let previous = 0; let current = 1; while (true) { yield current; const next = current + previous; previous = current; current = next; } } /* output: 1 1 2 3... 阅读全文
posted @ 2017-05-03 21:16 ax=null 阅读(142) 评论(0) 推荐(0)
摘要: { var a = 2 } console.log(a); // 2 { let b = 3; } console.log(b); // err b is not defined 阅读全文
posted @ 2017-05-01 13:55 ax=null 阅读(108) 评论(0) 推荐(0)