]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Possible fix: Using extend() with Moment's prototypes breaks IE < 9
authorXotic750 <xotic750@gmail.com>
Tue, 17 Sep 2013 23:01:41 +0000 (01:01 +0200)
committerXotic750 <xotic750@gmail.com>
Tue, 17 Sep 2013 23:01:41 +0000 (01:01 +0200)
https://github.com/moment/moment/issues/1114

moment.js

index c6d7222bc261927162e85e2993960702397c9e1f..1e76284df97ce08673facb98d942a0c04bf3fe19 100644 (file)
--- a/moment.js
+++ b/moment.js
     var moment,
         VERSION = "2.2.1",
         round = Math.round,
+
+        // variable for extend closure function
+        extend,
+
         i,
 
         // internal storage for language config files
     ************************************/
 
 
-    function extend(a, b) {
-        for (var i in b) {
-            if (b.hasOwnProperty(i)) {
-                a[i] = b[i];
-            }
+    extend = (function () {
+        var hasDontEnumBug = true,
+            dontEnums = [
+                "toString",
+                "toLocaleString",
+                "valueOf",
+                "hasOwnProperty",
+                "isPrototypeOf",
+                "propertyIsEnumerable",
+                "constructor"
+            ],
+            dontEnumsLength = dontEnums.length,
+            testObject = {
+                "toString": null
+            },
+            key;
+
+        for (key in testObject) {
+            hasDontEnumBug = false;
         }
-        return a;
-    }
+
+        return function extend(a, b) {
+            var name,
+                index,
+                dontEnum;
+
+            for (name in b) {
+                if (b.hasOwnProperty(name)) {
+                    a[name] = b[name];
+                }
+            }
+
+            if (hasDontEnumBug) {
+                for (index = 0; index < dontEnumsLength; index += 1) {
+                    dontEnum = dontEnums[index];
+                    if (b.hasOwnProprty(dontEnum)) {
+                        a[dontEnum] = b[dontEnum];
+                    }
+                }
+            }
+
+            return a;
+        };
+    }());
 
     function absRound(number) {
         if (number < 0) {