首页 > 代码库 > js总结(三):面向对象,oo模拟
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
js总结(三):面向对象,oo模拟
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。