-
-
Save gaybro8777/3ad4ff758d4da4e1e32c407aef71335c to your computer and use it in GitHub Desktop.
Merge as it should be ( == $.extend(true, {}, ...))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function myextend(/* args */){ | |
| var o = {} | |
| , args = Array.prototype.slice.call(arguments) | |
| , obj = args.shift() | |
| , src = args.shift(); | |
| for (var p in src){ | |
| if (src.hasOwnProperty(p)){ | |
| if (hasOwn.call(obj,p) && typeof obj[p] === 'object' && obj[p] !== null) { | |
| o[p] = myextend(obj[p],src[p]); | |
| } | |
| else { | |
| o[p] = src[p]; | |
| } | |
| } | |
| } | |
| return args.length > 0 ? myextend.apply(null, [o].concat(args)) : o; | |
| } | |
| /* | |
| var a = {}; | |
| var b = {a:'Hello', b:{}}; | |
| var c = {a:'Bye', b:{f:{d:2}}, c:1}; | |
| var r = myextend(a, b, c); | |
| alert(JSON.stringify(r,null,0)); //{"a":"Bye","b":{"f":{"d":2}},"c":1} | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment