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 深入精要
Head 物件概念
JavaScript 程式也被包在一個物件裡面,例如,當我們在編寫一個 web 瀏覽器環境的
JavaScript 程式時,JavaScript 會位於
window
物件之中,並且在裡面執行。這個
window
件就是「head 物件」,有時稱為「全域物件」。所有 JavaScript 的實作都需要使用一個
head 物件。
head 物件是 JavaScript 私下封裝使用者定義的程式碼產生的,它的用途是保存原生程式
碼,會與 JavaScript 預先封裝在一起。JavaScript 會將使用者定義的程式放在 head 物件之
中執行。我們接著來加以驗證,它與 web 瀏覽器有關。
接下來,我會建立一些 JavaScript 值,並驗證 head
window
物件之中的值。
Live Codeh ttp://jsbin.co m/upotis/edit
<!DOCTYPE html><html lang="en"><body><script>
var myStringVar = 'myString';
var myFunctionVar = function() {};
myString = 'myString';
myFunction = function() {};
console.log('myStringVar' in window); // 回傳 true
console.log('myFunctionVar' in window); // ...
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