Skip to Main Content
JavaScript 深入精要
book

JavaScript 深入精要

by Cody Lindley
December 2013
Intermediate to advanced content levelIntermediate to advanced
160 pages
2h 41m
Chinese
GoTop Information, Inc.
Content preview from JavaScript 深入精要
原型鏈概念
prototype
屬性是 JavaScript 為每一個
Function()
函式建立的物件,它的特別在於,它會
將使用
new
關鍵字建立的實例連回建構它們的建構函式,如此一來,各個實例就可以分
享或繼承共同的方法與屬性。重要的是,在查看屬性的時候,也會有分享的行為。還記
得在第一章,每當你在物件中查看或存取一個屬性時,程式會在物件及原型鏈中尋找那
個屬性。
JavaScript 會為所有的函式建立原型物件,無論你是否想要將那個函式當成建構式。
接下來,我會以
Array()
建構式建構一個陣列,並呼叫
join()
方法。
Live Codehttp://jsddle. net/javascript enlightenment/ 4L7ae/
<!DOCTYPE html><html lang="en"><body><script>
var myArray = new Array('foo', 'bar');
console.log(myArray.join()); // log 'foo, bar'
</script></body></html>
函式原型屬性
第八章
88
   
第八章
join()
方法並不
myArray
物件實例 定義的屬性,但 是不知
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaScript 設計模式

JavaScript 設計模式

Stoyan Stefanov
HTML5 錦囊妙計

HTML5 錦囊妙計

Christopher Schmitt, Kyle Simpson
jQuery Mobile建置與執行

jQuery Mobile建置與執行

Maximiliano Firtman

Publisher Resources

ISBN: 9789863470120