Lodash - runInContext method


Advertisements

Syntax

_.runInContext([context=root])

Create a new pristine lodash function using the context object.

Arguments

  • [context=root] (Object) − The context object.

Output

  • (Function) − Returns a new lodash function.

Example

var _ = require('lodash');

_.mixin({ 'foo': _.constant('foo') });
 
var lodash = _.runInContext();
lodash.mixin({ 'bar': lodash.constant('bar') });
 
console.log(_.isFunction(_.foo));
console.log(_.isFunction(_.bar));
console.log(lodash.isFunction(lodash.foo));
console.log(lodash.isFunction(lodash.bar));

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

true
false
false
true
lodash_util.htm
Advertisements