]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Format function now uses "instanceof" on a var rather than "typeof" on that var's... 766/head
authorgensym <david@gensym.org>
Sun, 5 May 2013 04:17:20 +0000 (23:17 -0500)
committergensym <david@gensym.org>
Sun, 5 May 2013 04:17:20 +0000 (23:17 -0500)
This fixes an incompatibility with ClojureScript, which defines String.prototype.call as a function.

moment.js
test/moment/string_prototype.js [new file with mode: 0644]

index 9b52be593d162d74ecdd416c2ccd329cd656467e..1b72884bc8a94c4ea3f37b70465c7a05e2bf3e0d 100644 (file)
--- a/moment.js
+++ b/moment.js
         return function (mom) {
             var output = "";
             for (i = 0; i < length; i++) {
-                output += typeof array[i].call === 'function' ? array[i].call(mom, format) : array[i];
+                output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
             }
             return output;
         };
diff --git a/test/moment/string_prototype.js b/test/moment/string_prototype.js
new file mode 100644 (file)
index 0000000..d4712d1
--- /dev/null
@@ -0,0 +1,17 @@
+var moment = require("../../moment");
+
+exports.add = {
+    "string prototype overrides call" : function(test) {
+        test.expect(1);
+
+        var prior = String.prototype.call;
+        String.prototype.call = function() { return null;};
+
+        var b = moment(new Date(2011, 7, 28, 15, 25, 50, 125));
+        test.equal(b.format('MMMM Do YYYY, h:mm a'), 'August 28th 2011, 3:25 pm');
+
+        String.prototype.call = prior;
+        test.done();
+    }
+
+};