1
|
/*!
|
2
|
* object-visit <https://github.com/jonschlinkert/object-visit>
|
3
|
*
|
4
|
* Copyright (c) 2015, 2017, Jon Schlinkert.
|
5
|
* Released under the MIT License.
|
6
|
*/
|
7
|
|
8
|
'use strict';
|
9
|
|
10
|
var isObject = require('isobject');
|
11
|
|
12
|
module.exports = function visit(thisArg, method, target, val) {
|
13
|
if (!isObject(thisArg) && typeof thisArg !== 'function') {
|
14
|
throw new Error('object-visit expects `thisArg` to be an object.');
|
15
|
}
|
16
|
|
17
|
if (typeof method !== 'string') {
|
18
|
throw new Error('object-visit expects `method` name to be a string');
|
19
|
}
|
20
|
|
21
|
if (typeof thisArg[method] !== 'function') {
|
22
|
return thisArg;
|
23
|
}
|
24
|
|
25
|
var args = [].slice.call(arguments, 3);
|
26
|
target = target || {};
|
27
|
|
28
|
for (var key in target) {
|
29
|
var arr = [key, target[key]].concat(args);
|
30
|
thisArg[method].apply(thisArg, arr);
|
31
|
}
|
32
|
return thisArg;
|
33
|
};
|