From: gensym Date: Sun, 5 May 2013 04:17:20 +0000 (-0500) Subject: Format function now uses "instanceof" on a var rather than "typeof" on that var's... X-Git-Tag: 2.1.0~32^2~4^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F766%2Fhead;p=thirdparty%2Fmoment.git Format function now uses "instanceof" on a var rather than "typeof" on that var's call to determine if the variable is a function. This fixes an incompatibility with ClojureScript, which defines String.prototype.call as a function. --- diff --git a/moment.js b/moment.js index 9b52be593..1b72884bc 100644 --- a/moment.js +++ b/moment.js @@ -597,7 +597,7 @@ 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 index 000000000..d4712d1fc --- /dev/null +++ b/test/moment/string_prototype.js @@ -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(); + } + +};