From 30291ce6e644529aed680bfbe98426cb05624f93 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 28 Feb 2013 20:34:14 -0800 Subject: [PATCH] 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 --- lodash.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index fa484326d..f8cce34a6 100644 --- a/lodash.js +++ b/lodash.js @@ -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,