Acme.BookStore.HttpApi.Host/node_modules/map-visit/README.md
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
# map-visit [](https://www.npmjs.com/package/map-visit) [](https://npmjs.org/package/map-visit) [](https://npmjs.org/package/map-visit) [](https://travis-ci.org/jonschlinkert/map-visit)
> Map `visit` over an array of objects.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save map-visit
```
## Usage
```js
var mapVisit = require('map-visit');
```
## What does this do?
**Assign/Merge/Extend vs. Visit**
Let's say you want to add a `set` method to your application that will:
* set key-value pairs on a `data` object
* extend objects onto the `data` object
* extend arrays of objects onto the data object
**Example using `extend`**
Here is one way to accomplish this using Lo-Dash's `extend` (comparable to `Object.assign`):
```js
var _ = require('lodash');
var obj = {
data: {},
set: function (key, value) {
if (Array.isArray(key)) {
_.extend.apply(_, [obj.data].concat(key));
} else if (typeof key === 'object') {
_.extend(obj.data, key);
} else {
obj.data[key] = value;
}
}
};
obj.set('a', 'a');
obj.set([{b: 'b'}, {c: 'c'}]);
obj.set({d: {e: 'f'}});
console.log(obj.data);
//=> {a: 'a', b: 'b', c: 'c', d: { e: 'f' }}
```
The above approach works fine for most use cases. However, **if you also want to emit an event** each time a property is added to the `data` object, or you want more control over what happens as the object is extended, a better approach would be to use `visit`.
**Example using `visit`**
后面还有 95 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
