gpt4 book ai didi

javascript - 为什么 Number.parseInt 和 global 的 parseInt 不同?

转载 作者:行者123 更新时间:2023-11-29 15:36:50 25 4
gpt4 key购买 nike

在 MDN 的 Number.parseInt部分,它说:

The Number.parseInt() method parses a string argument and returns an integer of the specified radix or base. This method behaves identically to the global function parseInt() and is part of ECMAScript 6 (its purpose is modularization of globals).

.. 但以下代码在最新的 firefox 上产生 false

console.log(Number.parseInt == parseInt)

那么它们只是相同吗?

最佳答案

AFAIK 你的比较(当应用于函数时)测试它是否是函数的完全相同的实例,这不是 - 它们恰好在内部具有相似的内容(代码)。您可以通过定义自己的 2 个恰好包含相似代码的函数来轻松地对其进行测试,例如两者都是“{alert('hi')}”。你会看到它们不是“==”

关于javascript - 为什么 Number.parseInt 和 global 的 parseInt 不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27394507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com