JavaScript 類型的包裝對(duì)象(Typed Wrappers)
更新時(shí)間:2011年10月27日 10:01:25 作者:
JavaScript 有一套類型的包裝對(duì)象,需要的朋友可以參考下。
例如:
new Boolean(false)
會(huì)返回一個(gè)對(duì)象,該對(duì)象有一個(gè) valueOf 方法會(huì)返回被包裝的值。這其實(shí)完全沒有必要,并且有時(shí)還令人困惑。不要使用 new Boolean、 new Number 或 new String。
此外也請(qǐng)避免使用 new Object 和 new Array??墒褂?{} 和 [] 來(lái)代替。
--------------------------------------------------------------------------------
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)
會(huì)返回一個(gè)對(duì)象,該對(duì)象有一個(gè) valueOf 方法會(huì)返回被包裝的值。這其實(shí)完全沒有必要,并且有時(shí)還令人困惑。不要使用 new Boolean、 new Number 或 new String。
此外也請(qǐng)避免使用 new Object 和 new Array??墒褂?{} 和 [] 來(lái)代替。
--------------------------------------------------------------------------------
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
相關(guān)文章
JavaScript 面向?qū)ο缶幊蹋?) 基礎(chǔ)
自從有了Ajax這個(gè)概念,JavaScript作為Ajax的利器,其作用一路飆升。JavaScript最基本的使用,以及語(yǔ)法、瀏覽器對(duì)象等等東東在這里就不累贅了。把主要篇幅放在如何實(shí)現(xiàn)JavaScript的面向?qū)ο缶幊谭矫妗?/div> 2010-05-05javascript面向?qū)ο笾甁avascript 繼承
所有面向?qū)ο蟮恼Z(yǔ)言都應(yīng)該有繼承的特性,JavaScript 也不例外。2010-05-05javascript 設(shè)計(jì)模式之單體模式 面向?qū)ο髮W(xué)習(xí)基礎(chǔ)
單體是在腳本加載時(shí)創(chuàng)建的,能將一系列有關(guān)聯(lián)的變量和方法組織為一個(gè)邏輯單元,邏輯單元里面的內(nèi)容通過(guò)單一的變量進(jìn)行訪問,也是筆記基礎(chǔ)與常用的面向?qū)ο蟮亩x方法。2010-04-04JavaScript isPrototypeOf和hasOwnProperty使用區(qū)別
JavaScript isPrototypeOf和hasOwnProperty的使用技巧,需要的朋友的朋友可以參考下。2010-03-03javascript 面向?qū)ο缶幊?聊聊對(duì)象的事
javascript是基于對(duì)象的編程語(yǔ)言。從window到document,從方法到類,從object到Array都是對(duì)象。2009-09-09最新評(píng)論