JavaScript 類型的包裝對象(Typed Wrappers)
更新時間:2011年10月27日 10:01:25 作者:
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.
原文: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
相關(guān)文章
JavaScript 面向?qū)ο缶幊蹋?) 基礎(chǔ)
自從有了Ajax這個概念,JavaScript作為Ajax的利器,其作用一路飆升。JavaScript最基本的使用,以及語法、瀏覽器對象等等東東在這里就不累贅了。把主要篇幅放在如何實現(xiàn)JavaScript的面向?qū)ο缶幊谭矫妗?/div> 2010-05-05javascript面向?qū)ο笾甁avascript 繼承
所有面向?qū)ο蟮恼Z言都應(yīng)該有繼承的特性,JavaScript 也不例外。2010-05-05javascript 設(shè)計模式之單體模式 面向?qū)ο髮W(xué)習(xí)基礎(chǔ)
單體是在腳本加載時創(chuàng)建的,能將一系列有關(guān)聯(lián)的變量和方法組織為一個邏輯單元,邏輯單元里面的內(nèi)容通過單一的變量進行訪問,也是筆記基礎(chǔ)與常用的面向?qū)ο蟮亩x方法。2010-04-04JavaScript isPrototypeOf和hasOwnProperty使用區(qū)別
JavaScript isPrototypeOf和hasOwnProperty的使用技巧,需要的朋友的朋友可以參考下。2010-03-03最新評論