diff --git a/lodash.js b/lodash.js index 14bced112..f511c67d6 100644 --- a/lodash.js +++ b/lodash.js @@ -13230,7 +13230,9 @@ * var lodash = _.noConflict(); */ function noConflict() { - root._ = oldDash; + if (root._ === this) { + root._ = oldDash; + } return this; } diff --git a/test/test.js b/test/test.js index d1eaaa37a..ff1f771f8 100644 --- a/test/test.js +++ b/test/test.js @@ -14297,6 +14297,20 @@ } }); + QUnit.test('should restore `_` only if `lodash` is the current `_` value', function(assert) { + assert.expect(2); + + if (!isModularize) { + var object = root._ = {}; + assert.strictEqual(_.noConflict(), oldDash); + assert.strictEqual(root._, object); + root._ = oldDash; + } + else { + skipTest(assert, 2); + } + }); + QUnit.test('should work with a `root` of `this`', function(assert) { assert.expect(2);