Last active
November 27, 2017 07:56
-
-
Save luckylooke/8433aa366bb680014cd0 to your computer and use it in GitHub Desktop.
angular.merge polyfill for angular < 1.4.0
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
| if (!angular.merge) { | |
| angular.merge = (function mergePollyfill() { | |
| function setHashKey(obj, h) { | |
| if (h) { | |
| obj.$$hashKey = h; | |
| } else { | |
| delete obj.$$hashKey; | |
| } | |
| } | |
| function baseExtend(dst, objs, deep) { | |
| var h = dst.$$hashKey; | |
| for (var i = 0, ii = objs.length; i < ii; ++i) { | |
| var obj = objs[i]; | |
| if (!angular.isObject(obj) && !angular.isFunction(obj)) continue; | |
| var keys = Object.keys(obj); | |
| for (var j = 0, jj = keys.length; j < jj; j++) { | |
| var key = keys[j]; | |
| var src = obj[key]; | |
| if (deep && angular.isObject(src)) { | |
| if (angular.isDate(src)) { | |
| dst[key] = new Date(src.valueOf()); | |
| } else { | |
| if (!angular.isObject(dst[key])) dst[key] = angular.isArray(src) ? [] : {}; | |
| baseExtend(dst[key], [src], true); | |
| } | |
| } else { | |
| dst[key] = src; | |
| } | |
| } | |
| } | |
| setHashKey(dst, h); | |
| return dst; | |
| } | |
| return function merge(dst) { | |
| return baseExtend(dst, [].slice.call(arguments, 1), true); | |
| } | |
| })(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment