javascript - One line of code writing for underscore.js source code
巴扎黑
巴扎黑 2017-05-19 10:40:56
0
1
460
  _.isNaN = function(obj) {
        return _.isNumber(obj) && isNaN(obj); //_.isNumber ?
    }
  • _.isNumber is not defined in other parts. According to the && operator, the _.isNumber method is not defined, so _.isNumber(obj) is false, so what is returned is isNaN( obj), why not just return isNaN(obj)?

巴扎黑
巴扎黑

reply all(1)
phpcn_u1582

I found the point. . . I saw it wrong, it turned out to be here

 // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError, isMap, isWeakMap, isSet, isWeakSet.
    _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error', 'Symbol', 'Map', 'WeakMap', 'Set', 'WeakSet'], function(name) {
        _['is' + name] = function(obj) {
            return toString.call(obj) === '[object ' + name + ']';
        };
    });
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!