js总结(三):面向对象,oo模拟
http://aralejs.org/class/docs/competitors.html
http://javascript.crockford.com/prototypal.html
Here is another formulation:
Object.prototype.begetObject = function () { function F() {} F.prototype = this; return new F(); }; newObject = oldObject.begetObject();
2007-04-02
The problem with the object
function is that it is global, and globals are clearly problematic. The problem with Object.prototype.begetObject
is that it trips up incompetent programs, and it can produce unexpected results when begetObject
is overridden.
So I now prefer this formulation:
if (typeof Object.create !== ‘function‘) { Object.create = function (o) { function F() {} F.prototype = o; return new F(); }; } newObject = Object.create(oldObject);
2008-04-07
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。