开发者

Javascript global objects stops working after prototype change!

I don't if I am missing something obvious, but when I do something like below:-

Object.prototype.inherit = function(fromClass) {
  fromClass.apply(this, Array.prototype.slice.call(arguments, 1));

  for(var key in fromClass.prototype){
    if(typeof fromClass.prototype[key] == 'function')
        this.prototype[key] = fromClass.prototype[key];
  }
};

The开发者_开发百科n I can no longer work with any objects. I always get undefined. Similary when I try to 'inject' some method into Array.prototype then arrays stop working! I am using Firefox 4.0.1.

Am I missing something?


PLEASE, PLEASE, PLEASE, PLEASE DO NOT EXTEND OBJECT.PROTOTYPE.

Thank you.

Now getting on to your question, what do you mean you can no longer work with objects? You're going to break for-in loops, but short of that everything should still work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜