JS 對象介紹
JavaScript is an Object Oriented Programming (OOP) language.
JS是面向?qū)ο蟮木幊陶Z言(面向?qū)ο螅?(這里是基于對象還是面向?qū)ο蟠蠹铱梢运阉飨拢?BR>An OOP language allows you to define your own objects and make your own variable types.
OOP語言可以讓你自定義對象和變量類型。
--------------------------------------------------------------------------------
Object Oriented Programming
被安置對象的編程
JavaScript is an Object Oriented Programming (OOP) language. An OOP language allows you to define your own objects and make your own variable types.
JS是(OOP)語言,這就可以讓你定義....(和上面的重復(fù))
However, creating your own objects will be explained later, in the Advanced JavaScript section. We will start by looking at the built-in JavaScript objects, and how they are used. The next pages will explain each built-in JavaScript object in detail.
然而,我們將晚些在高級JS里介紹建立自定義對象。我們將開始觀察內(nèi)建JS對象和如何使用它們。下頁將詳細(xì)介紹每個(gè)內(nèi)建JS對象
Note that an object is just a special kind of data. An object has properties and methods.
注意,對象只是特殊類型的數(shù)據(jù)。對象有屬性和方法
--------------------------------------------------------------------------------
Properties
屬性
Properties are the values associated with an object.
屬性是對象的相連值
In the following example we are using the length property of the String object to return the number of characters in a string:
下面的例子我么使用了字符串對象的長度屬性來返回字符的數(shù)量:
<script type="text/javascript">
var txt="Hello World!"
document.write(txt.length)
</script>
The output of the code above will be:
上面的代碼就會輸出:
12
--------------------------------------------------------------------------------
Methods
方法
Methods are the actions that can be performed on objects.
對象的方法可以執(zhí)行行為。
In the following example we are using the toUpperCase() method of the String object to display a text in uppercase letters:
下面的例子使用了字符串對象的toUpperCase()方法來顯示出文字的大寫:
<script type="text/javascript">
var str="Hello world!"
document.write(str.toUpperCase())
</script>
The output of the code above will be:
上面的代碼輸出:
HELLO WORLD!
相關(guān)文章
JavaScript接口實(shí)現(xiàn)代碼 (Interfaces In JavaScript)
接口是面向?qū)ο缶幊汤锏闹匾匦?,遺憾的是JavaScript并沒有提供對接口的支持!怎么實(shí)現(xiàn)接口呢?2010-06-06JavaScript 類的定義和引用 JavaScript高級培訓(xùn) 自定義對象
在Java語言中,我們可以定義自己的類,并根據(jù)這些類創(chuàng)建對象來使用,在Javascript中,我們也可以定義自己的類,例如定義User類、Hashtable類等等。2010-04-04javascript中的對象創(chuàng)建 實(shí)例附注釋
為了讓你的js代碼更加的專業(yè)與代碼的條理性,很多情況下都是定義成對象的方式來書寫代碼,想深入的朋友可以參考下。2011-02-02Javascript面向?qū)ο髷U(kuò)展庫代碼分享
最近一直在用js做項(xiàng)目,遇到了許多需要應(yīng)用面向?qū)ο髞碓O(shè)計(jì)的功能,由于js對OOP的原生支持還不是很完善,所以就寫了一個(gè)面向?qū)ο蟮臄U(kuò)展庫用做底層支持,現(xiàn)在把它單獨(dú)整理出來,完善了一些功能,在這里分享一下2012-03-03

JavaScript面向?qū)ο笤O(shè)計(jì)二 構(gòu)造函數(shù)模式