摘要:
regexp.exechttp://www.w3school.com.cn/js/jsref_exec_regexp.aspregexp.testhttp://www.w3school.com.cn/js/jsref_test_regexp.aspstring.matchhttp://www.w3school.com.cn/js/jsref_match.aspstring.replacehttp://www.w3school.com.cn/js/jsref_replace.aspstring.searchhttp://www.w3school.com.cn/js/jsref_search.as 阅读全文
摘要:
判断是否为数组1 var is_array = function(value) {2 return value && typeof value === 'object' && typeof value.length === 'number' && typeof value.splice === 'function' && !(value.propertyIsEnumerable('length'));3 };4 5 //使用方法6 var arrayValue = [ 阅读全文
摘要:
1 var mammal = function(spec) { 2 var that = {}; 3 4 that.get_name = function() { 5 return spec.name; 6 }; 7 8 that.says = function() { 9 return spec.saying || '';10 };11 return that;12 };13 14 var myMammal = mammal({15 ... 阅读全文
摘要:
1 var mammal = function(spec) { 2 var that = {}; 3 4 that.saying = function() { 5 return spec.saying; 6 }; 7 8 that.get_name = function() { 9 return spec.name;10 };11 12 that.says = function() {13 return this.sayi... 阅读全文
摘要:
1 if (typeof Object.beget !== 'function') { 2 Object.beget = function(o) { 3 var F = function() {}; 4 F.prototype = o; 5 return new F(); 6 }; 7 } 8 9 var myMammal = {10 name: 'Herb the Mammal',11 get_name: function() {12 return this.name;13 },14 ... 阅读全文
摘要:
Object.create方法创建一个使用原对象作为其原型的新对象。1 if (typeof Object.create !== 'function') {2 Object.create = function (o) {3 function F() {}4 F.prototype = o;5 return new F();6 };7 }8 newObject = Object.create(oldObject); 阅读全文
摘要:
1 var memoizer = function(memo, fundamental) { 2 var shell = function(n) { 3 var result = memo[n]; 4 if (typeof result !== 'number') { 5 result = fundamental(shell, n); 6 memo[n] = result; 7 } 8 ... 阅读全文
摘要:
var memoizer = function(memo, fundamental) { var shell = function(n) { var result = memo[n]; if (typeof result !== 'number') { result = fundamental(shell, n); memo[n] = result; } return result; ... 阅读全文
摘要:
1 Function.prototype.method = function(name, func) { 2 if (!this.prototype[name]) { 3 this.prototype[name] = func; 4 } 5 }; 6 7 Function.method('curry', function() { 8 var slice = Array.prototype.slice, 9 args = slice.apply(arguments),10 that = this;11 retur... 阅读全文
摘要:
1 var serial_maker = function() { 2 //返回一个用来产生唯一字符串的对象。 3 //唯一字符串由两部分组成:前缀+序列号。 4 //该对象包含一个设置前缀的方法,一个设置序列号的方法,和一个产生唯一字符串的 gensym 方法。 5 var prefix = ''; 6 var seq = 0; 7 return { 8 set_prefix: function(p) { 9 prefix = String... 阅读全文