首页 > Web开发 > 详细

js总结(三):面向对象,oo模拟

时间:2014-10-07 23:32:54      阅读:321      评论:0      收藏:0      [点我收藏+]

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模拟

原文:http://www.cnblogs.com/danghuijian/p/4009971.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!