From 340f7e3acb689d949755993cd5d33d217d97b2d9 Mon Sep 17 00:00:00 2001 From: gensym Date: Sat, 4 May 2013 23:17:20 -0500 Subject: [PATCH] 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. --- moment.js | 2 +- test/moment/string_prototype.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/moment/string_prototype.js 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(); + } + +}; -- 2.47.2