MCPcopy Create free account
hub / github.com/hoothin/UserScripts / cloneObject

Function cloneObject

FlashViewer-HTML5 Video/flashViewer.user.js:433–451  ·  view source on GitHub ↗
(obj, deep)

Source from the content-addressed store, hash-verified

431
432 //对象克隆,接受{}和[]
433 function cloneObject(obj, deep) {
434 var value;
435 var ret = Array.isArray(obj) ? [] : {};
436
437 for (var key in obj) {
438 if (!obj.hasOwnProperty(key)) continue;
439
440 value = obj[key];
441
442 if (value === obj) {// 引用自己
443 ret[key] = ret;
444 } else if (deep && (Array.isArray(value) || Object.prototype.toString.call(value) == '[object Object]')) {
445 ret[key] = cloneObject(value, true);
446 } else {
447 ret[key] = value;
448 };
449 };
450 return ret;
451 };
452
453 //检测属性支持 (property 非 attribute)
454 //返回带前缀的可以直接执行是属性

Callers 1

contentScriptFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected