coffeescript-cookbook/coffeescript-cookbook.github.com — Issue #38: Extension of built-in native objects in recipes
Author: fhemberger
Created: 2012-02-23 12:10:38+00:00
State: open

Browsing the recipes, I found one pattern to be quite common: The extension of build-in native objects.
It's totally fine to back-port ECMAScript 5 methods (as long you make sure, you don't overwrite existing implementations by accident), e.g.:

unless String::trim then String::trim = -> @replace /^\s+|\s+$/g, ""

On the other hand, modifying objects you don't own is considered a bad practice in JavaScript (whereas it's quite common in other languages like Ruby):
- [Maintainable JavaScript: Don’t modify objects you don’t own](http://www.nczonline.net/blog/2010/03/02/maintainable-javascript-dont-modify-objects-you-down-own/) by Nicholas C. Zakas
- [Extending built-in native objects. Evil or not?](http://perfectionkills.com/extending-built-in-native-objects-evil-or-not/)

Personally, I think those examples should either be reworked or have a note in the "Discussion" section, that this should be used with caution, linking the articles above.

What do you think?