欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

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

程序员文章站 2022-05-20 17:19:27
...
例如:

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.

原文:http://demon.tw/programming/javascript-typed-wrappers.html
相关标签: Typed Wrappers