Java中一元+的作用是什么? [英] What is unary + used for in Javascript?

查看:58
本文介绍了Java中一元+的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Underscore.js

  _.map = _.collect = function(obj, iterator, context) {
    var results = [];
    if (obj == null) return results;
    if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
    each(obj, function(value, index, list) {
      results[results.length] = iterator.call(context, value, index, list);
    });
    if (obj.length === +obj.length) results.length = obj.length;
    return results;
  };

我想知道if (obj.length === +obj.length)是什么?

推荐答案

+length是一种将任何内容转换为数字的方法.

+length is a method to convert anything to a number.

如果是数字,则值不变,并且比较返回true.
如果不是数字,则断言为假.

If it's a number, the value doesn't change, and the comparison returns true.
If it's not a number, the assertion is false.

这篇关于Java中一元+的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆