Make setting context work in older ES3 environments that will use values, named after built-in constructors, for the creation of literals.

Former-commit-id: 981139db2a30f9c69d3e616021f697b8403dee26
This commit is contained in:
John-David Dalton
2013-02-28 20:34:14 -08:00
parent 890c2eb564
commit 30291ce6e6

View File

@@ -129,7 +129,11 @@
* @returns {Function} Returns the `lodash` function.
*/
function runInContext(context) {
context = context ? _.defaults({}, context, _.pick(window, contextProps)) : window;
// Avoid issues with some ES3 environments that attempt to use values, named
// after built-in constructors like `Object`, for the creation of literals.
// ES5 clears this up by stating that literals must use built-in constructors.
// See http://es5.github.com/#x11.1.5.
context = context ? _.defaults(window.Object(), context, _.pick(window, contextProps)) : window;
/** Native constructor references */
var Array = context.Array,