javascript - Why does jQuery Extend Deep Copy not recursively copy an object? -


i've searched everywhere , found similar questions answers didn't address issue apologize if seems repeat, appears experimenting jquery's deep copy function doesn't work it's described (or maybe i'm misreading description).

here's example demonstrating problem i'm having: http://jsfiddle.net/wcysh/

or download: https://github.com/kevroy314/jquery-extend-test

why data in previous copy changed when deep copy manipulated?

for one, aren't creating normal objects.

i'm looking @ source code jquery 1.7.2 extend.

https://github.com/jquery/jquery/blob/master/src/core.js

and i'm noticing line:

if ( deep && copy && ( jquery.isplainobject(copy) || (copyisarray = jquery.isarray(copy)) 

has evaluate true deep copying. copy part of current object being copied.

but aren't creating "plain" objects. creating objects generated invoking constructor new operator.

now, in isplainobject, seems these lines have evaluated. (where hasown hasown = object.prototype.hasownproperty

    try {         // not own constructor property must object         if ( obj.constructor &&             !hasown.call(obj, "constructor") &&             !hasown.call(obj.constructor.prototype, "isprototypeof") ) {             return false;         }     } catch ( e ) {         // ie8,9 throw exceptions on host objects #9897         return false;     } 

and there's concludes it's not "plainobject".

this makes sense when consider objects constructor probably ought created via constructor or @ least use sort of "clone" method you'd see in other languages/frameworks.


Comments

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -