Skip to main content
added 80 characters in body
Source Link
Peter Mortensen
  • 31.5k
  • 22
  • 110
  • 134

Extending the javascript Array objectJavaScript Array object is a really bad idea because you introduce new properties (your custom methods) into for-infor-in loops which can break existing scripts. A few years ago the authors of the PrototypePrototype library had to re-engineer their library implementation to remove just this kind of thing.

If you don't need to worry about compatibility with other javascriptJavaScript running on your page, go for it, otherwise, I'd recommend the more awkward, but safer free-standing function solution.

Extending the javascript Array object is a really bad idea because you introduce new properties (your custom methods) into for-in loops which can break existing scripts. A few years ago the authors of the Prototype library had to re-engineer their library implementation to remove just this kind of thing.

If you don't need to worry about compatibility with other javascript running on your page, go for it, otherwise, I'd recommend the more awkward, but safer free-standing function solution.

Extending the JavaScript Array object is a really bad idea because you introduce new properties (your custom methods) into for-in loops which can break existing scripts. A few years ago the authors of the Prototype library had to re-engineer their library implementation to remove just this kind of thing.

If you don't need to worry about compatibility with other JavaScript running on your page, go for it, otherwise, I'd recommend the more awkward, but safer free-standing function solution.

Source Link
Mason Houtz
Mason Houtz

Extending the javascript Array object is a really bad idea because you introduce new properties (your custom methods) into for-in loops which can break existing scripts. A few years ago the authors of the Prototype library had to re-engineer their library implementation to remove just this kind of thing.

If you don't need to worry about compatibility with other javascript running on your page, go for it, otherwise, I'd recommend the more awkward, but safer free-standing function solution.