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