search

Home  >  Q&A  >  body text

javascript - One line of code writing for underscore.js source code

  _.isNaN = function(obj) {
        return _.isNumber(obj) && isNaN(obj); //_.isNumber ?
    }
巴扎黑巴扎黑2771 days ago513

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-19 10:42:56

    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 + ']';
            };
        });
    

    reply
    0
  • Cancelreply