Skip to content

runInContext

js
_.runInContext([context=root])

使用 context 对象创建一个新的原始 lodash 函数。

¥Create a new pristine lodash function using the context object.

新增于

¥Since

1.1.0

参数

¥Arguments

  1. [context=root] (对象):上下文对象。

    ¥[context=root] (Object): The context object.

返回

¥Returns

(函数):返回一个新的 lodash 函数。

¥(Function): Returns a new lodash function.

示例

¥Example

js
_.mixin({ 'foo': _.constant('foo') });

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

_.isFunction(_.foo);
// => true
_.isFunction(_.bar);
// => false

lodash.isFunction(lodash.foo);
// => false
lodash.isFunction(lodash.bar);
// => true

// Create a suped-up `defer` in Node.js.
var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;

Lodash v4.17 中文网 - 粤ICP备13048890号