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 設計模式
192
   
第八章
在這個例子中,文件只被更新了一次,造成了單次的 reow/repaint,相對於前一個不好的
例子,每個段落都造成了更新。
文件片段對於在樹中新增節點很有用。不過當你要更新樹裡面某個現有的部分,你仍然可
以將變動批次處理。你可以將你要改變的子樹從根部複製一份,對複本做完所有的改變,
再用複本替換掉原本的節點:
事件
瀏覽器 script 編寫的另一個部分─事件,例如 clickmouseover 等等,也充滿了不一致,
是另一個挫折之源。再次強調,為了同時支援(第 9 版之前的)IE W3C 標準,所必須
耗費的雙倍工作,你可以用 JavaScript 函式庫來帶走大部分。
讓我們來仔細看一遍重點,因為在較簡單的頁面,或是要快速完成的工作中,你也許並不
一定會使用現成的函式庫,或者也許你正在建立你自己的函式庫。[185]
事件處理
事件處理皆從在元素上附加事件監聽器開始。假設你有個按鈕,在你每次點擊時會將計數
器加一。你可以使用一個內嵌的
onclick
屬性,這樣就可以跨瀏覽器運作,但卻違反了關
注點分離和漸進式增強的原則。所以你應該努力讓附加監聽器寫在 JavaScript 裡面,在所
有的標記之外。
clone 進行操作...
當你完成之後:
DOM 和瀏覽器的模式
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