documentcloud/underscore — pull request #1123 by jridgewell (2013-05-21 02:31:02+00:00)
Title: Getters setters

This pull request will allow `_.extend` to properly copy over getters/setters, provided the ECMA5 functions `Object.defineProperty` and `Object.getOwnPropertyDescriptor` are available. If not, it will fall back to assigning the property on the destination object, as it does now.

#275 attempted this, but was rejected. I've used ECMA5 functions instead of the deprecated ones. I'm also checking for functions before using them, to prevent breaking in unsupported browsers.

It also attempts to detect IE 8's faulty `Object.defineProperty` implementation ( https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/defineProperty#ie8-specific and http://blogs.msdn.com/b/ie/archive/2010/09/07/transitioning-existing-code-to-the-es5-getter-setter-apis.aspx ), in which case it'll use the old method.

Unfortunately the test I've added breaks testing in IE 8. msdn.com says you have to use `__defineGetter__` and `__defineSetter__` which are the deprecated functions #275 had... but in testing they would result in runtime errors. Without the tests I've added, everything works fine in IE 8 even with my changed `_.extend`.

I've tested in:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.29.13 (KHTML, like Gecko) Version/6.0.4 Safari/536.29.13
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31