Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Basic JavaScript Coding Patterns
Search
Ji Guang
November 09, 2012
Technology
650
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Basic JavaScript Coding Patterns
no
Ji Guang
November 09, 2012
More Decks by Ji Guang
See All by Ji Guang
Adobe Edge Preview
jiguang
0
84
Blogging Like A Hacker
jiguang
5
290
Signature Tool
jiguang
1
89
Javascript正则表达式
jiguang
3
700
虚拟机调试
jiguang
1
120
DNS缓存清除
jiguang
0
150
哈工大90周年校庆吉祥物评比
jiguang
0
190
Other Decks in Technology
See All in Technology
2026-09-18 gotanda.sre Terraformで複数環境作ったり、複数Stateに分割したりそれとTerragrunt / Terraform multi envs and multi states
masasuzu
4
700
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.6k
AIエージェントの一手は 誰も見ていない - Falco拡張OSS「Prempti」とeBPFで サーバーレス実行基盤を二層防御する
keitah
0
490
LLMに渡さなかった仕事
nanaism
0
1.4k
Why Agent Cost Needs Observability
nttcom
0
140
現場で役立つ技術負債の効果的な返済方法
masuda220
PRO
11
5k
バイブコーディング時代のWebアプリ開発入門~Cloud Runで学ぶセキュアなビルドとデプロイ
waiwai2111
1
140
EventBridge に「合流」はない ― サーバーレスのワークフローを育てるということ / No Join in EventBridge
yusukeshimizu
2
470
絵ではじめるKubernetesセキュリティ
aoi1
4
700
AI de Idea
kawaguti
PRO
2
130
Goodbye ShellScript, Hello File-based App
shunsock
0
690
AgentCore Runtime上にAgentic Coding基盤を構築・展開する際の設計ポイントと限界点 / Design considerations and limitations when building an agentic coding platform on AgentCore Runtime
har1101
5
680
Featured
See All Featured
How GitHub (no longer) Works
holman
316
150k
Believing is Seeing
oripsolob
1
220
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
250
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
280
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
240
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
610
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
340
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
560
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Transcript
Basic JavaScript Coding Patterns @laserji 2012-05-16
Variable Definition var a = 0, b=1, c=“xxx”; //
shorter var obj = {}; // faster var arr = []; var regex = /something/;
Default Value arg = arg || „default‟; // fallback
e || e = window.event; return a || „default‟
Condition answer = obj && obj.xx && obj.xx. property
if( obj.xx ){ … } // don‟t: if(obj != null){} if( a === b){ … } // always if(document.getElementById){ … } // ability detect
Ternary check ? value1 : value2; var foo
= (condition) ? value1 : value2; return (condition) ? value1 : value2; foo = predicate ? ”one” : predicate ? ”two” : ”default”;
Iteration var name = value[i]; i++ var
name = values[i++];
DOM Operation el.style.display = „none‟; // offline //
operation el.style.display = „block‟; var fragment = document.createDocumentFragment(); innerHTML // Be careful with NodeList var imges = document.getElementsByTagName(„img‟);
Event Agent attach event at a higher level
<div id=“highLevelElement”> <div><ul><li> … </li></ul></div> </div> $(„#id‟).click(function(evt){ … });
Object as a Namespace var MYAPP = {};
MYAPP.namespace(„event‟);
Chaining var obj = new MYAPP.dom.Element(„span‟); obj.setText(„hello‟)
.setStyle(„color‟, „red‟) .serStyle(„font‟, „Verdana‟); document.body.appendChild(obj); // return this
Function (function(){ … })(); // block scope (function($){
… }(jQuery);
Configure Obj function foo( conf ){ … }
foo ({ key1 : 1, key2 : 2 })
Type Conversion +‟010‟ === 10 Number(„010‟) === 10
parseInt(„010‟, 10) === 10 10 + “” === “10”
Prototype Array.prototype.forEach = function(){ … } // only
for forward compatible
Loop for ( var I = 0, j =
xx.length; i<j; i++){ … } // cache var I = 0, j = xx.lenght; for (;i<j; i++){ … } // hoisting for ( var I in foo ){ if( foo.hasOwnProperty(i) ){ // required console.log(i) } }
New Feature Array.forEach() // use it when possible
getElementsByClassName() querySlectorAll()
Lazy Definition function lazyDef(){ if(condition1){ lazyDef =
function(){ … }; }else if(condition2){ lazyDef = function(){ … }; } return lazyDef(); }
Private Functions as Public Methods var MYAPP = {};
MYAPP.dom = (function(){ var _setStyle = function(el, prop, value){ console.log(„setStyle‟); }; return { setStyle: _setStyle }; })(); // MYAPP.dom.setStyle = otherFunc
Design Patterns Singleton Factory Decorator Observer
……
Thank You!