js 递归实现深度克隆与浅克隆
2021-01-22 20:15
标签:vararg force alt axios 深度 hat ORC cts param 直接看代码吧,浅显易懂并配有英文注解, 代码来源注释:作者在看axios源码时看到的片段。 js 递归实现深度克隆与浅克隆 标签:vararg force alt axios 深度 hat ORC cts param 原文地址:https://www.cnblogs.com/xiaolantian/p/13282988.html
/**
* Iterate over an Array or an Object invoking a function for each item.
*
* If `obj` is an Array callback will be called passing
* the value, index, and complete array for each item.
*
* If ‘obj‘ is an Object callback will be called passing
* the value, key, and complete object for each property.
*
* @param {Object|Array} obj The object to iterate
* @param {Function} fn The callback to invoke for each item
*/
function forEach(obj, fn) {
// Don‘t bother if no value provided
if (obj === null || typeof obj === ‘undefined‘) {
return;
}
// Force an array if not already something iterable
if (typeof obj !== ‘object‘) {
/*eslint no-param-reassign:0*/
obj = [obj];
}
if (isArray(obj)) {
// Iterate over array values
for (var i = 0, l = obj.length; i
下一篇:最新的web.xml配置代码