开发者

Is there something wrong with extending native Javascript prototypes?

开发者 https://www.devze.com 2023-03-26 23:46 出处:网络
I have seen some people regard extending the natives prototypes in Javascript with disdain. I was thinking about doing it, because of syntactic convenience. I.e.

I have seen some people regard extending the natives prototypes in Javascript with disdain. I was thinking about doing it, because of syntactic convenience. I.e.

function(array, element)

can be more cumbersome to write and less readable than

array.function(element)

But the seco开发者_JAVA技巧nd can only be acheived (AFAIK) by extending the Array prototype. Is there something wrong with extending native prototypes, and will doing this somehow haunt be me later?


It can conflict with other libraries trying to do the same.

It can conflict with future methods added to native objects.

If anyone is using for (var i in array) without proper hasOwnProperty() checks, their code may/probably will break because the new method may show up in the iteration in older browsers.

0

精彩评论

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