polarmobile/coffeescript-style-guide — Issue #4: Why "Do not modify native objects"?
Author: paulmillr
Created: 2011-12-24 20:19:37+00:00
State: open

It's obvious that extending native objects is bad if you're doing it improperly:

```coffeescript
String::capitalize = ->
this[0].toUpperCase() + this[1...]

console.log char for char of 'str'
# => 0, 1, 2, capitalize
```

But ES5 has `Object.defineProperty`, which allows you to extend objects with non-enumerable properties:

```coffeescript
Object.defineProperty String, 'capitalize' value: ->
this[0].toUpperCase() + this[1...]

console.log char for char of 'str'
# => 0, 1, 2
```