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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2020-05-13 我要评论
例如:

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:/https://img.qb5200.com/download-x/demon.tw/programming/javascript-typed-wrappers.html

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们