From: Iskren Chernev Date: Wed, 8 Jul 2015 11:20:53 +0000 (+0800) Subject: Fix function check to workaround old browsers, fixes #2325 X-Git-Tag: 2.10.5~20^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82c98f70f50bc2154e630656c6510926ba2fa1fe;p=thirdparty%2Fmoment.git Fix function check to workaround old browsers, fixes #2325 --- diff --git a/src/lib/parse/regex.js b/src/lib/parse/regex.js index 23091a083..9e7d6788c 100644 --- a/src/lib/parse/regex.js +++ b/src/lib/parse/regex.js @@ -22,8 +22,15 @@ import hasOwnProp from '../utils/has-own-prop'; var regexes = {}; +function isFunction (sth) { + // https://github.com/moment/moment/issues/2325 + return typeof sth === 'function' && + Object.prototype.toString.call(sth) === '[object Function]'; +} + + export function addRegexToken (token, regex, strictRegex) { - regexes[token] = typeof regex === 'function' ? regex : function (isStrict) { + regexes[token] = isFunction(regex) ? regex : function (isStrict) { return (isStrict && strictRegex) ? strictRegex : regex; }; }