Skip to content

Commit 0a30871

Browse files
committed
added title, description and reference to general patterns
1 parent 797fa2a commit 0a30871

13 files changed

+68
-7
lines changed

‎general-patterns/access-to-global-object.html‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<metacharset="utf-8">
66
</head>
77
<body>
88
<script>
9+
/* Title: Access to the Global Object
10+
Description: access the global object without hard-coding the identifier window
11+
*/
12+
913
// access to the Global Object
1014
// this should work in ES3, ES5 and ES5-strict.
1115
varglobal=(function(){

‎general-patterns/avoiding-eval.html‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<metacharset="utf-8">
66
</head>
77
<body>
88
<script>
9+
/* Title: Avoiding eval()
10+
Description: avoid using eval()
11+
*/
12+
913
// antipattern
1014
varproperty="name";
1115
alert(eval("obj."+property));

‎general-patterns/avoiding-implied-typecasting.html‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<metacharset="utf-8">
66
</head>
77
<body>
88
<script>
9+
/* Title: Implied Typecasting
10+
Description: avoid implied typecasting
11+
*/
12+
913
varzero=0;
1014

1115
// antipattern

‎general-patterns/built-in-prototypes.html‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<metacharset="utf-8">
66
</head>
77
<body>
88
<script>
9+
/* Title: (Not) Augmenting Built-in Prototypes
10+
Description: only augment built-in prototypes when certain conditions are met
11+
*/
12+
913
if(typeofObject.protoype.myMethod!=="function"){
1014
Object.protoype.myMethod=function(){
1115
// implementation...

‎general-patterns/conditionals.html‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<metacharset="utf-8">
66
</head>
77
<body>
88
<script>
9+
/* Title: Conditionals
10+
Description: pattern and antipattern of using if else
11+
*/
12+
913
// NOTE: Paul Irish states that the first statement is only an antipattern when optimizing for
1014
// low-bandwidth source (such as for a bookmarklet.
1115
// Using the first statement will generally outperform the regex in a loop, and is faster than the

‎general-patterns/for-in-loops.html‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<metacharset="utf-8">
66
</head>
77
<body>
88
<script>
9+
/* Title: for-in loops
10+
Description: optimized for-in loops
11+
*/
12+
913
// the object
1014
varman={
1115
hands: 2,
@@ -60,6 +64,9 @@
6064
console.log(i,":",man[i]);
6165
}
6266
}
67+
68+
// reference
69+
// http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
6370
</script>
6471
</body>
6572
</html>

‎general-patterns/for-loops.html‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<metacharset="utf-8">
66
</head>
77
<body>
88
<script>
9+
/* Title: for loops
10+
Description: optimized for loops
11+
*/
12+
913
// sub-optimal loop
1014
for(vari=0;i<myarray.length;i++){
1115
// do something with myarray[i]
@@ -36,6 +40,9 @@
3640
}
3741

3842
}
43+
44+
// reference
45+
// http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
3946
</script>
4047
</body>
4148
</html>

‎general-patterns/globals.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
</head>
77
<body>
88
<script>
9+
/* Title: Minimizing Globals
10+
Description: create and access a global variable in a browser environment
11+
*/
12+
913
functionsum(x,y){
1014
// antipatten: implied global
1115
result=x+y;

‎general-patterns/hoisting.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
</head>
77
<body>
88
<script>
9+
/* Title: Hoisting
10+
Description: var statements anywhere in a function act as if the variables were declared at the top of the function
11+
*/
12+
913
// antipattern
1014
myname="global";// global variable
1115
functionfunc(){

‎general-patterns/minimizing-globals.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
</head>
77
<body>
88
<script>
9+
/* Title: Minimizing Globals
10+
Description: create and access a global variable in a browser environment
11+
*/
12+
913
myglobal="hello";// antipattern
1014
console.log(myglobal);// "hello"
1115
console.log(window.myglobal);// "hello"

0 commit comments

Comments
(0)