JavaScript 类型的包装对象(Typed Wrappers)

标签: , , ,

JavaScript 有一套类型的包装对象。例如:

new Boolean(false)

会返回一个对象,该对象有一个 valueOf 方法会返回被包装的值。这其实完全没有必要,并且有时还令人困惑。不要使用 new Boolean、 new Number 或 new String。

此外也请避免使用 new Object 和 new Array。可使用 {} 和 [] 来代替。


JavaScript has a set of typed wrappers. For example:

new Boolean(false)

produces an object that has a valueOf method that returns the wrapped value. This turns out to be completely unnecessary and occasionally confusing. Don’t use new Boolean or new Number or new String.

Also avoid new Object and new Array. Use {} and [] instead.

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. VBS实现GB2312转Unicode
  2. 88行代码实现俄罗斯方块游戏(含讲解)
  3. VBS中的左移位&右移位运算
  4. C语言函数strcpy strncpy和strlcpy
  5. 确定Windows XP到底是UCS-2的还是UTF-16的

留下回复