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.
精彩评论