摘要: 第六章 OO programming的继承中的Parasitic Combination Inheritance,用了inheritPrototype方法实现继承,方法如下:function inheritPrototype(subType, superType){var prototype = object(superType.prototype); //create objectprototype.constructor = subType; //augment objectsubType.prototype = prototype; //assign object}调用inheritPr 阅读全文
posted @ 2013-09-11 15:03 sunnyfish 阅读(203) 评论(0) 推荐(0)
摘要: 1: 1 && 32: 1 && "foo" || 03: 1 || "foo" && 04:(1,2,3)5: x = {shift:[].shift};x.shift();x.length;6:{foo:1}[0] eval('{foo:1}[0]')7:[true, false][+true, +false]8:++'52'.split('')[0]9:a: b: c: d: e: f: g: 1, 2, 3, 4, 5;10:{a: 1, b: 2}[ 阅读全文
posted @ 2013-09-05 19:58 sunnyfish 阅读(277) 评论(0) 推荐(0)
摘要: 最近又看了一下Douglas Crockford的经典文章Classical Inheritance in JavaScript和玉伯写的 Crockford uber方法中的陷阱。Douglas写的uber方法在处理“断层”继承时会有问题,并且继承没有恢复constructor。玉伯改写的方法,增加了superclass属性来记录父类构造器,继承时还原了constructor,并且利用hasOwnProperty跳过断层,并且迭代时再次判断了f和 this[name] 是否相等。玉伯的方法在测试“断层”时,能跳过断层实现继承,但是结果还是有问题。理论上,最后两行应该都输出 D1,D2,D5。 阅读全文
posted @ 2013-08-29 21:34 sunnyfish 阅读(224) 评论(0) 推荐(0)