码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-10-08 00:04:04      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   java   for   sp   c   on   cti   

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   io   ar   java   for   sp   c   on   cti   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!