摘要:
var str = "url(../images/kk.png)"; var pattern = /\w+\.\w{3}/g; console.log(str.match(pattern)[0]); // 'kk.png' 阅读全文
摘要:
function Person(name) { this.name = name; this.flag = 0; Object.defineProperty(this, 'name', { get: function() { return name;}, set: function(newName) { if (this.flag) { n... 阅读全文
摘要:
function Person(name) { this.name = name; Object.defineProperty(this, 'name', { get: function() { return name;}, set: function(newName) { if (name) { return;} return name = n... 阅读全文
摘要:
var o = Object.create(null); console.log(o); // {} console.log(o.constructor); // undefined console.log(o.__proto__); // undefined console.log(o instanceof Object); // false 阅读全文
摘要:
var a = {}; var b = a; var o = {}; o[a] = 1; o[b] = 2; o[a]++; console.log(o[b]); 阅读全文
摘要:
var closure = (function(){ var arr = [1, 3]; function printArr() { console.log(arr); }; return [arr, printArr]; }()); closure[1](); // [1, 3] closure[0][1] = 2; closure[1](... 阅读全文
摘要:
var closure = (function(){ var arr = [1, 3]; return { getA: (function() { return arr; }()), printArr: function() { console.log(arr); }... 阅读全文
摘要:
var closure = (function(){ var arr = [1, 3]; return { getA: function() { return arr; }, printArr: function() { console.log(arr); } ... 阅读全文
摘要:
如何判断 instanceof 返回真 只要判断右边的值是否是左边对象的构造函数或原型对象上的构造函数即可 // example var arr = []; 由于: 1. arr.constructor === Array 2. arr.__proto__ === Array.prototype 3. arr.__poto__.proto__ === Object.prototype 所... 阅读全文
摘要:
function selectSort(arr) { var len = arr.length; for (var i = 0; i arr[j]) { var temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; }... 阅读全文