JavaScript克隆对象的三个实用方法

摘要: 方法1function clone(obj){ var o; if(typeof obj == "object"){ if(obj === null){ o = null; }else{ if(obj instanceof Array){ o = []; for(var i = 0, len = obj.length; i < len; i++){ o.push(clone(obj[i])); } }else{ o = {}; for(var k in obj){ o[k] = clone(obj[k]); } } } }else{ o = obj; } return 阅读全文
posted @ 2011-04-06 20:19 snandy 阅读(3040) 评论(5) 推荐(3) 编辑

JavaScript中链式调用之研习

摘要: 方法链一般适合对一个对象进行连续操作(集中在一句代码)。一定程度上可以减少代码量,缺点是它占用了函数的返回值。一、对象链:方法体内返回对象实例自身(this)function ClassA(){ this.prop1 = null; this.prop2 = null; this.prop3 = null;}ClassA.prototype = { method1 : function(p1){ this.prop1 = p1; return this; }, method2 : function(p2){ this.prop2 = p2; return this; }, method... 阅读全文
posted @ 2011-04-06 11:03 snandy 阅读(5104) 评论(6) 推荐(4) 编辑

我的函数链之演变

摘要: 最易读版function chain(obj){ function fun(){ if (arguments.length == 0){ return fun.obj; } var methodName = arguments[0], methodArgs = [].slice.call(arguments,1); fun.obj[methodName].apply(fun.obj,methodArgs); return fun; } fun.obj = obj; return fun;}易读版function chain(obj){ return function(){ va... 阅读全文
posted @ 2011-04-06 09:48 snandy 阅读(2026) 评论(3) 推荐(1) 编辑
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

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