JS Object Deep Dive copy (keyed out from Requirejs)

Source: Internet
Author: User

1 varOP =Object.prototype,2Ostring =op.tostring,3Hasown =Op.hasownproperty;4 5 functionIsfunction (IT) {6     returnOstring.call (IT) = = = ' [Object Function] ';7 };8 9 functionIsArray (IT) {Ten     returnOstring.call (IT) = = = ' [Object Array] '; One }; A functionHasprop (obj, prop) { -     returnHasown.call (obj, prop); - }; the functionEachprop (obj, func) { -     varprop; -      for(Propinchobj) { -         if(Hasprop (obj, prop)) { +             if(func (Obj[prop], prop)) { -                  Break; +             } A         } at     } - }; - /** - * Simple function to mix in properties from source into target, - * But only if Target does not already has a property of the the same name. -  * in * @param {target} destination object - * Source object @param {source} to * @param {force} enforces overriding properties of the target object + * @param {deepstringmixin} is a deep copy recursive operation -  * the * @returns {target} *  */ $ functionmixin (target, source, Force, deepstringmixin) {Panax Notoginseng     if(source) { -Eachprop (Source,function(value, prop) { the             if(Force | |!)Hasprop (target, prop)) { +                 if(Deepstringmixin &&typeofValue = = = ' object ' && value && A!isarray (value) &&!isfunction (value) && the! (ValueinstanceofRegExp)) { +  -                     if(!Target[prop]) { $Target[prop] = {}; $                     } - mixin (Target[prop], value, Force, deepstringmixin); -}Else { theTarget[prop] =value; -                 }Wuyi             } the         }); -     } Wu     returnTarget; - }; About  $  - Call: - varobj = { -Name: ' Tom ', AAge:19, + children:{ theName: ' Jack ', -Age:30 $     } the }; the varObj2 = Mixin ({},obj,false,true); theObj.children.name= ' Marry '; theConsole.log (OBJ2);

JS Object Deep Dive copy (keyed out from Requirejs)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.