mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Ensure _.noConflict operates on root and not context.
This commit is contained in:
@@ -738,7 +738,7 @@
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/** Used to restore the original `_` reference in `_.noConflict`. */
|
||||
var oldDash = context._;
|
||||
var oldDash = root._;
|
||||
|
||||
/** Used to detect if a method is native. */
|
||||
var reIsNative = RegExp('^' +
|
||||
@@ -11558,7 +11558,7 @@
|
||||
* var lodash = _.noConflict();
|
||||
*/
|
||||
function noConflict() {
|
||||
context._ = oldDash;
|
||||
root._ = oldDash;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
15
test/test.js
15
test/test.js
@@ -11443,23 +11443,30 @@
|
||||
QUnit.module('lodash.noConflict');
|
||||
|
||||
(function() {
|
||||
test('should return the `lodash` function', 1, function() {
|
||||
test('should return the `lodash` function', 2, function() {
|
||||
if (!isModularize) {
|
||||
var oldDash = root._;
|
||||
strictEqual(_.noConflict(), oldDash);
|
||||
|
||||
if (!(isRhino && typeof require == 'function')) {
|
||||
notStrictEqual(root._, oldDash);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
root._ = oldDash;
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
skipTest(2);
|
||||
}
|
||||
});
|
||||
|
||||
test('should work with a `context` of `this`', 2, function() {
|
||||
test('should work with a `root` of `this`', 2, function() {
|
||||
if (!isModularize && !document && _._object) {
|
||||
var fs = require('fs'),
|
||||
vm = require('vm'),
|
||||
expected = {},
|
||||
context = vm.createContext({ '_': expected }),
|
||||
context = vm.createContext({ '_': expected, 'console': console }),
|
||||
source = fs.readFileSync(filePath);
|
||||
|
||||
vm.runInContext(source + '\nthis.lodash = this._.noConflict()', context);
|
||||
|
||||
Reference in New Issue
Block a user