Skip to Content
JavaScript 設計模式
book

JavaScript 設計模式

by Stoyan Stefanov
March 2012
Intermediate to advanced
244 pages
4h 42m
Chinese
GoTop Information, Inc.
Content preview from JavaScript 設計模式
106
   
第五章
如果需要,你也可以利用「函式也是物件」這個特性,將一些資料用「靜態」(static
屬性的方式儲存在
Sandbox()
建構式裡。
最後,你可以依據所需的模組的類型,來產生不同實體,且這些實體都可以彼此獨立
工作。
我們來看看可以如何逐步實作
Sandbox()
建構式和它的模組,以支援上述這些功能。
新增模組
在真正實作建構式之前,我們先來看看可以如何逐步新增模組。
Sandbox()
建構式也是物件,所以你可以新增一個名為
modules
的靜態屬性。這屬性又是
另一個物件,包含許多名值對,鍵值是模組名稱,而值則是每個模組的實作函式:
在這範例中,我們加入了
dom
event
ajax
模組,這些都是在各個函式庫,或者複雜的
網頁應用上很常見的一些功能。
實作這些模組的每個函式都接受
box
實體為參數,可能會在函式中新增屬性或方法到這個
實體中。[103]
如有必要則存取 Sandbox 的原型
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JavaScript 之美

JavaScript 之美

Anton Kovalyov
重構 JavaScript

重構 JavaScript

Evan Burchard

Publisher Resources

ISBN: 9789862764190