摘要: var singleton = (function(){ var instance; return function () { if (instance) return instance; instance = this; return instance; } }()); var obj = new singleton(... 阅读全文
posted @ 2017-04-30 13:24 ax=null 阅读(135) 评论(0) 推荐(0) 编辑
摘要: var obj = { foo: "hi", f1: function() { function f2(that) { console.log(that); } f2(this.foo); } }; obj.f1(); // hi Function.pr... 阅读全文
posted @ 2017-04-29 03:15 ax=null 阅读(3922) 评论(0) 推荐(0) 编辑
摘要: var num = 1;var num2 = (num = 3, ++num);console.log(num2); // 4 阅读全文
posted @ 2017-04-28 00:42 ax=null 阅读(297) 评论(0) 推荐(0) 编辑
摘要: var f = ( function() { var a = 1; return () => { a++; console.log(a); } }()); // 2 3 4 f() f() f() 阅读全文
posted @ 2017-04-28 00:34 ax=null 阅读(96) 评论(0) 推荐(0) 编辑
摘要: function getArrayRandomVal(arr) { var len = arr.length, index = Math.floor(len * Math.random()); return arr[index]; } 阅读全文
posted @ 2017-04-27 18:30 ax=null 阅读(294) 评论(0) 推荐(0) 编辑
摘要: var type = (function() { var getType = function(o) { return Object.prototype.toString.call(o) }; return { isNumber: function(o) { return getType(o) === '[object Number]'; }, isBoolean: ... 阅读全文
posted @ 2017-04-27 16:37 ax=null 阅读(655) 评论(0) 推荐(0) 编辑
摘要: function random(min, max) { return min + Math.floor(Math.random() * (max - min + 1)); } 阅读全文
posted @ 2017-04-27 15:36 ax=null 阅读(1116) 评论(0) 推荐(0) 编辑
摘要: 1 + '1' = 11; 1 + true = 2; 1 + [] = '1' 阅读全文
posted @ 2017-04-14 19:41 ax=null 阅读(174) 评论(0) 推荐(0) 编辑
摘要: var arr = [ 1, [2], [[[3]]], [4, [5] ] ]; function unidimensionalArray (arr) { return (arr + '').split(',').map(x => Number(x)); } console.log(unidimensionalArray(arr)); // [ 1, 2, 3, 4, 5 ] //... 阅读全文
posted @ 2017-04-13 22:17 ax=null 阅读(1332) 评论(0) 推荐(0) 编辑
摘要: just do it 阅读全文
posted @ 2016-10-30 19:40 ax=null 阅读(83) 评论(0) 推荐(0) 编辑