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
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
上一篇: 怎样把下载到本地的demo放到可以外网访问的服务器?
下一篇: 安利一下:连安利都转型互联网+啦!
推荐阅读
-
解析JavaScript面向对象概念中的Object类型与作用域
-
同一页面多个商品倒计时JS 基于面向对象的javascript
-
解析JavaScript面向对象概念中的Object类型与作用域
-
重学js之JavaScript 面向对象的程序设计(创建对象)
-
javascript Base类 包含基本的方法_js面向对象
-
同一页面多个商品倒计时JS 基于面向对象的javascript_时间日期
-
面向对象的javascript(笔记)_js面向对象
-
面向对象的javascript(笔记)_js面向对象
-
javascript类式继承新的尝试_js面向对象
-
JS基于面向对象实现的放烟花效果_javascript技巧