Giter VIP home page Giter VIP logo

Comments (6)

aleen42 avatar aleen42 commented on August 19, 2024 2

哈哈哈哈,找到原因了。若是使用 obj !== +objnew Number(1) 照样会出现问题:

var a = new Number(1);
a; /** => Number {[[PrimitiveValue]]: 1} */
+a; /** => 1 */
a !== +a; /** => true */

+操作符会把 Number 类型转换成字面值

from underscore-analysis.

pod4g avatar pod4g commented on August 19, 2024

然后补充一下ES规范中,关于NaN的部分。这个才是最权威的。哈哈。

关于isNaN函数 从规范可看到,调用这个函数先会执行toNumber,这个就是所谓的转型。顾名思义,就是把isNaN的参数先toNumber一下。。

关于toNumber的说明和规定

英语渣,暂没有找到中文版的ES6规范。想看看ES6中关于Number.isNaN的说明

from underscore-analysis.

juemin90 avatar juemin90 commented on August 19, 2024

在lodash3.10.1版本中,.isNaN(new Number(0))会返回false,.isNaN(new Number(NaN))会返回true,这应该是解决了bug的结果吧?

from underscore-analysis.

lessfish avatar lessfish commented on August 19, 2024

@juemin90 返回是正确的,不过 lodash 不熟,以前有 bug?

from underscore-analysis.

wiekern avatar wiekern commented on August 19, 2024

_.isNaN(new Number(0)) 应该返回 false. 现在修复了,见 issue jashkenas/underscore#2257

from underscore-analysis.

nightn avatar nightn commented on August 19, 2024

ES6 的 Number.isNaN 和目前 underscore 的 _.isNaN 除了对 new Number(NaN) 返回结果不一致外,对于 new Object(NaN) 的返回结果也不一致。

from underscore-analysis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.