> For the complete documentation index, see [llms.txt](https://lodash.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lodash.shujuwajue.com/util/runincontext.md).

# \_.runInContext

**语法：**

```javascript
_.runInContext([context=root])
```

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L1420)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.runincontext)

**描述：**

创建一个给定`context`上下文对象的原始的`lodash`函数。

**开始版本：**&#x31;.1.0

**参数：**

* `[context=root] (Object)`: 上下文对象。

**返回值：**

* `(Function)`: 返回新的 lodash 对象

**例子：**

```javascript
_.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;
```
