Extending Object.prototype JavaScript

前端 未结 5 517
终归单人心
终归单人心 2020-11-27 05:30

I am not asking if this is okay:

Object.prototype.method = function(){};

This is deemed evil by pretty much everyone, cons

5条回答
  •  盖世英雄少女心
    2020-11-27 05:59

    I think it's fine if it works in your target environment.

    Also I think prototype extension paranoia is overblown. As long as you use hasOwnProperty() like a good developer that it's all fine. Worst case, you overload that property elsewhere and lose the method. But that's your own fault if you do that.

提交回复
热议问题