diff --git a/code-reuse-patterns/borrowing-methods.html b/code-reuse-patterns/borrowing-methods.html index af64d06..99938f0 100644 --- a/code-reuse-patterns/borrowing-methods.html +++ b/code-reuse-patterns/borrowing-methods.html @@ -1,82 +1,82 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/code-reuse-patterns/cp1-default.html b/code-reuse-patterns/cp1-default.html index 9455320..e16f25f 100644 --- a/code-reuse-patterns/cp1-default.html +++ b/code-reuse-patterns/cp1-default.html @@ -1,49 +1,50 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/code-reuse-patterns/cp2-rent-a-constructor.html b/code-reuse-patterns/cp2-rent-a-constructor.html index 2b9762d..429c14e 100644 --- a/code-reuse-patterns/cp2-rent-a-constructor.html +++ b/code-reuse-patterns/cp2-rent-a-constructor.html @@ -1,60 +1,60 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/code-reuse-patterns/cp3-rent-and-set-prototype.html b/code-reuse-patterns/cp3-rent-and-set-prototype.html index 4b2336b..1d71593 100644 --- a/code-reuse-patterns/cp3-rent-and-set-prototype.html +++ b/code-reuse-patterns/cp3-rent-and-set-prototype.html @@ -1,45 +1,45 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/code-reuse-patterns/cp4-share-the-prototype.html b/code-reuse-patterns/cp4-share-the-prototype.html index ddee768..93eb152 100644 --- a/code-reuse-patterns/cp4-share-the-prototype.html +++ b/code-reuse-patterns/cp4-share-the-prototype.html @@ -1,44 +1,45 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/code-reuse-patterns/cp5-a-temporary-constructor.html b/code-reuse-patterns/cp5-a-temporary-constructor.html index fd2c474..86f7397 100644 --- a/code-reuse-patterns/cp5-a-temporary-constructor.html +++ b/code-reuse-patterns/cp5-a-temporary-constructor.html @@ -1,75 +1,77 @@  - -JavaScript Patterns - - - - - + // reference + // http://shop.oreilly.com/product/9780596806767.do + + \ No newline at end of file diff --git a/code-reuse-patterns/inheritance-by-copying-properties.html b/code-reuse-patterns/inheritance-by-copying-properties.html index 8036978..6fdb245 100644 --- a/code-reuse-patterns/inheritance-by-copying-properties.html +++ b/code-reuse-patterns/inheritance-by-copying-properties.html @@ -1,78 +1,78 @@  - -JavaScript Patterns - - - - - + console.log(dad.reads === kid.reads); // false + kid.reads.paper = false; + + + // reference + // http://shop.oreilly.com/product/9780596806767.do + + \ No newline at end of file diff --git a/code-reuse-patterns/klass.html b/code-reuse-patterns/klass.html index 119f0f2..af182f0 100644 --- a/code-reuse-patterns/klass.html +++ b/code-reuse-patterns/klass.html @@ -1,158 +1,167 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + - - \ No newline at end of file +< +/body> +< /html> \ No newline at end of file diff --git a/code-reuse-patterns/mix-ins.html b/code-reuse-patterns/mix-ins.html index d67c858..3ef8e98 100644 --- a/code-reuse-patterns/mix-ins.html +++ b/code-reuse-patterns/mix-ins.html @@ -1,40 +1,40 @@  - -JavaScript Patterns - - - - - + // reference + // http://addyosmani.com/resources/essentialjsdesignpatterns/book/#mixinpatternjavascript + // http://shop.oreilly.com/product/9780596806767.do + + \ No newline at end of file diff --git a/code-reuse-patterns/prototypal-inheritance.html b/code-reuse-patterns/prototypal-inheritance.html index 2a397d7..c62d4f7 100644 --- a/code-reuse-patterns/prototypal-inheritance.html +++ b/code-reuse-patterns/prototypal-inheritance.html @@ -1,77 +1,79 @@  - -JavaScript Patterns - - - - - + + // reference + // http://shop.oreilly.com/product/9780596806767.do + + \ No newline at end of file diff --git a/design-patterns/builder.html b/design-patterns/builder.html index 3d6f17e..045bc3f 100644 --- a/design-patterns/builder.html +++ b/design-patterns/builder.html @@ -1,35 +1,35 @@  - -JavaScript Patterns - - - - - - + // reference + // http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#builderpatternjquery + + \ No newline at end of file diff --git a/design-patterns/chain-of-responsibility.html b/design-patterns/chain-of-responsibility.html index 967d28c..6604ca7 100644 --- a/design-patterns/chain-of-responsibility.html +++ b/design-patterns/chain-of-responsibility.html @@ -1,66 +1,66 @@  - -JavaScript Patterns - - - - - + // reference + // https://gist.github.com/1174982 + + \ No newline at end of file diff --git a/design-patterns/command.html b/design-patterns/command.html index a2c88f5..15f21d4 100644 --- a/design-patterns/command.html +++ b/design-patterns/command.html @@ -1,44 +1,44 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/design-patterns/decorator.html b/design-patterns/decorator.html index 0c2505a..87d5bf2 100644 --- a/design-patterns/decorator.html +++ b/design-patterns/decorator.html @@ -1,55 +1,55 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/design-patterns/facade.html b/design-patterns/facade.html index f48c927..21bd85e 100644 --- a/design-patterns/facade.html +++ b/design-patterns/facade.html @@ -1,27 +1,27 @@  - -JavaScript Patterns - - - - - + // reference + // http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#facadepatternjavascript + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/design-patterns/factory.html b/design-patterns/factory.html index 7e57114..8c1ec28 100644 --- a/design-patterns/factory.html +++ b/design-patterns/factory.html @@ -1,88 +1,88 @@  - -JavaScript Patterns - - - - - + var o = jsp.dom.factory('Link'); + o.url = 'http://google.com'; + o.insert(document.body); + + var taskManager = {}; + + taskManager.update = function () { + console.log('update'); + } + + taskManager.read = function () { + console.log('read'); + } + + var type = 'update'; + var task; + + if (type === 'update') { + task = new taskManager.update(); + } + + if (type === 'read') { + task = new taskManager.read(); + } + + taskManager.factory = function (typeType) { + return new taskManager[typeType]; + } + + task = new taskManager[type]; + + /*** Built-in Object Factory ***/ + var o = new Object(), + n = new Object(1), + s = Object('1'), + b = Object(true); + + // test + o.constructor === Object; // true + n.constructor === Number; // true + s.constructor === String; // true + b.constructor === Boolean; // true + + // reference + // http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#factorypatternjavascript + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/design-patterns/iterator.html b/design-patterns/iterator.html index 3656602..b82b4bf 100644 --- a/design-patterns/iterator.html +++ b/design-patterns/iterator.html @@ -1,71 +1,71 @@  - -JavaScript Patterns - - - - - + next:function () { + var element; + if (!this.hasNext()) { + return null; + } + element = data[index]; + index = index + 2; + return element; + }, + + hasNext:function () { + return index < length; + }, + + rewind:function () { + index = 0; + }, + + current:function () { + return data[index]; + } + + }; + }()); + + // this loop logs 1, then 3, then 5 + while (agg.hasNext()) { + console.log(agg.next()); + } + + // go back + agg.rewind(); + console.log(agg.current()); // 1 + + // reference + // http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#iteratorpatternjquery + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/design-patterns/mediator.html b/design-patterns/mediator.html index ef96727..06fa34f 100644 --- a/design-patterns/mediator.html +++ b/design-patterns/mediator.html @@ -1,91 +1,91 @@  - -JavaScript Patterns - - - - - + // all the player + players:{}, + + // initialization + setup:function () { + var players = this.players; + players.home = new Player('Home'); + players.guest = new Player('Guest'); + }, + + // someone plays, update the score + played:function () { + var players = this.players, + score = { + Home:players.home.points, + Guest:players.guest.points + }; + + scoreboard.update(score); + }, + + // handle user interactions + keypress:function (e) { + e = e || window.event; // IE + if (e.which === 49) { // key "1" + mediator.players.home.play(); + return; + } + if (e.which === 48) { // key "0" + mediator.players.guest.play(); + return; + } + } + }; + + // go! + mediator.setup(); + window.onkeypress = mediator.keypress; + + // game over in 30 seconds + setTimeout(function () { + window.onkeypress = null; + console.log('Game over!'); + }, 30000); + + // reference + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/design-patterns/observer.html b/design-patterns/observer.html index 4f11ff9..797696f 100644 --- a/design-patterns/observer.html +++ b/design-patterns/observer.html @@ -1,83 +1,83 @@  - -JavaScript Patterns - - - - - + // reference + // http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#observerpatternjavascript + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/design-patterns/proxy.html b/design-patterns/proxy.html index b73de17..c00bd49 100644 --- a/design-patterns/proxy.html +++ b/design-patterns/proxy.html @@ -1,213 +1,243 @@  -JavaScript Patterns - - + JavaScript Patterns + + -

Dave Matthews vids

-

Toggle Checked

-
    -
  1. Gravedigger
  2. -
  3. Save Me
  4. -
  5. Crush
  6. -
  7. Don't Drink The Water
  8. -
  9. Funny the Way It Is
  10. -
  11. What Would You Say
  12. -
- - +

Dave Matthews vids

+

Toggle Checked

+
    +
  1. Gravedigger
  2. +
  3. Save Me
  4. +
  5. Crush
  6. +
  7. Don't Drink The + Water
  8. +
  9. Funny the Way It + Is
  10. +
  11. What Would You Say +
  12. +
+ + \ No newline at end of file diff --git a/design-patterns/singleton.html b/design-patterns/singleton.html index a2f5af6..36555d2 100644 --- a/design-patterns/singleton.html +++ b/design-patterns/singleton.html @@ -1,149 +1,148 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/design-patterns/strategy.html b/design-patterns/strategy.html index c23f5b1..e73ea4b 100644 --- a/design-patterns/strategy.html +++ b/design-patterns/strategy.html @@ -1,116 +1,116 @@ - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/dom-and-browser/event-handling.html b/dom-and-browser/event-handling.html index 6287755..0283b07 100644 --- a/dom-and-browser/event-handling.html +++ b/dom-and-browser/event-handling.html @@ -1,58 +1,58 @@  - -JavaScript Patterns - - - - - - + function myHandler(e) { + var src, parts; + // get event and source element + e = e || window.event; + src = e.target || e.srcElement; + // actual work: update label + parts = src.innerHTML.split(": "); + parts[1] = parseInt(parts[1], 10) + 1; + src.innerHTML = parts[0] + ": " + parts[1]; + // no bubble + if (typeof e.stopPropagation === "function") { + e.stopPropagation(); + } + if (typeof e.cancelBubble !== "undefined") { + e.cancelBubble = true; + } + // prevent default action + if (typeof e.preventDefault === "function") { + e.preventDefault(); + } + if (typeof e.returnValue !== "undefined") { + e.returnValue = false; + } + } + + \ No newline at end of file diff --git a/function-patterns/callback.html b/function-patterns/callback.html index 68be058..1a22771 100644 --- a/function-patterns/callback.html +++ b/function-patterns/callback.html @@ -1,51 +1,52 @@ - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/function-patterns/callbacks-and-scope.html b/function-patterns/callbacks-and-scope.html index 5a9733b..dfc9b50 100644 --- a/function-patterns/callbacks-and-scope.html +++ b/function-patterns/callbacks-and-scope.html @@ -1,44 +1,44 @@ - -JavaScript Patterns - - - - - + var findNodes = function (callback, callback_obj) { + if (typeof callback === "string") { + callback = callback_obj[callback]; + } + + // ... + if (typeof callback === "function") { + callback.call(callback_obj, found); + } + // ... + }; + + \ No newline at end of file diff --git a/function-patterns/configuration-objects.html b/function-patterns/configuration-objects.html index e1112ca..715b31f 100644 --- a/function-patterns/configuration-objects.html +++ b/function-patterns/configuration-objects.html @@ -1,25 +1,25 @@ - -JavaScript Patterns - - - - - + // reference + // http://www.jspatterns.com/ + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/function-patterns/currying.html b/function-patterns/currying.html index 018e8e5..22f7030 100644 --- a/function-patterns/currying.html +++ b/function-patterns/currying.html @@ -1,176 +1,188 @@ - -JavaScript Patterns - - - - - + + /* Here are some example uses - I use these with a functional immutable list structure implemented in js + but they also work ok for normal higher order functions over arrays. + */ + + var plus = curry(function () { + var result = 0; + for (var i = 0; i < arguments.length; ++i) { + result += arguments[i]; + } + return result; + }, 2); + + /* Now you can call + plus(3,2) // normal call + plus(3) // partial application (returns a function that adds 3 to its argument) + plus(3)(2) // complete application (returns 5) + plus()(3)()()(2) // returns 5 + plus(3, 2, 4, 5) // the normal call can optionally take more than the minimum number of arguments + plus(3)(2, 3, 5) // the last application can too. + */ + + var minus = curry(function (x) { + var result = x; + for (var i = 1; i < arguments.length; ++i) { + result -= arguments[i]; + } + return result; + }, 2); + + /* flip switches the order of the first two arguments on a function. It is curried itself and + the function it returns is curried too. Particularly useful if you want a function that subtracts a number */ + + var flip = curry(function (func) { + return curry(function (a, b) { + return func(b, a); + }, 2); + }); + + /* for example + minus(5) // returns a function that takes its argument away from 5 + flip(minus)(5) // returns a function that takes 5 away from its argument + */ + + \ No newline at end of file diff --git a/function-patterns/enforcing-new-in-constructors.html b/function-patterns/enforcing-new-in-constructors.html index f1d1073..7075d2a 100644 --- a/function-patterns/enforcing-new-in-constructors.html +++ b/function-patterns/enforcing-new-in-constructors.html @@ -1,23 +1,23 @@ - -JavaScript Patterns - - - - - + // reference + // http://www.jspatterns.com/ + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/function-patterns/immediate-functions.html b/function-patterns/immediate-functions.html index ca10fcf..716312e 100644 --- a/function-patterns/immediate-functions.html +++ b/function-patterns/immediate-functions.html @@ -1,28 +1,28 @@ - -JavaScript Patterns - - - - - + // reference + // http://www.jspatterns.com/ + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + diff --git a/function-patterns/immediate-object-initialization.html b/function-patterns/immediate-object-initialization.html index 272cab9..b7c57c2 100644 --- a/function-patterns/immediate-object-initialization.html +++ b/function-patterns/immediate-object-initialization.html @@ -1,36 +1,36 @@ - -JavaScript Patterns - - - - - + // you can also define utility methods + gimmeMax:function () { + return this.maxwidth + "x" + this.maxheight; + }, + + // initialize + init:function () { + console.log(this.gimmeMax()); + // more init tasks... + } + }).init(); + + // reference + // http://www.jspatterns.com/ + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/function-patterns/init-time-branching.html b/function-patterns/init-time-branching.html index db140e2..8553feb 100644 --- a/function-patterns/init-time-branching.html +++ b/function-patterns/init-time-branching.html @@ -1,60 +1,60 @@ - -JavaScript Patterns - - - - - + // reference + // http://www.jspatterns.com/ + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/function-patterns/memoization.html b/function-patterns/memoization.html index dc26714..a539129 100644 --- a/function-patterns/memoization.html +++ b/function-patterns/memoization.html @@ -1,80 +1,80 @@ - -JavaScript Patterns - - - - - + // preferred method 1 + // only one argument using param + + var myFunc = function (param) { + if (!myFunc.cache.hasOwnProperty(param)) { + var result = {}; + // ... expensive operation ... + myFunc.cache[param] = result; + } + return myFunc.cache[param]; + }; + + // cache storage + myFunc.cache = {}; + + + // preferred method 2 + // multiple arguments using JSON stringify + + var myFunc = function () { + var cachekey = JSON.stringify(Array.prototype.slice.call(arguments)), + result; + if (!myFunc.cache[cachekey]) { + result = {}; + // ... expensive operation ... + myFunc.cache[cachekey] = result; + } + return myFunc.cache[cachekey]; + }; + + // cache storage + myFunc.cache = {}; + + + // preferred method 3 + // multiple arguments using arguments.callee + + var myFunc = function (param) { + var f = arguments.callee, + result; + if (!f.cache[param]) { + result = {}; + // ... expensive operation ... + f.cache[param] = result; + } + return f.cache[param]; + }; + + // cache storage + myFunc.cache = {}; + + \ No newline at end of file diff --git a/function-patterns/returning-functions.html b/function-patterns/returning-functions.html index 27c99bb..5ddb2b0 100644 --- a/function-patterns/returning-functions.html +++ b/function-patterns/returning-functions.html @@ -1,40 +1,40 @@ - -JavaScript Patterns - - - - - + // reference + // http://www.jspatterns.com/ + // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate + + \ No newline at end of file diff --git a/function-patterns/self-defining-functions.html b/function-patterns/self-defining-functions.html index 15f7135..07b0a86 100644 --- a/function-patterns/self-defining-functions.html +++ b/function-patterns/self-defining-functions.html @@ -1,42 +1,42 @@ - -JavaScript Patterns - - - - - + var scareMe = function () { + alert("Boo!"); + scareMe = function () { + alert("Double boo!"); + }; + }; + + // 1. adding a new property + scareMe.property = "properly"; + // 2. assigning to a different name + var prank = scareMe; + // 3. using as a method + var spooky = { + boo:scareMe + }; + // calling with a new name + prank(); // "Boo!" + prank(); // "Boo!" + console.log(prank.property); // "properly" + // calling as a method + spooky.boo(); // "Boo!" + spooky.boo(); // "Boo!" + console.log(spooky.boo.property); // "properly" + // using the self-defined function + scareMe(); // Double boo! + scareMe(); // Double boo! + console.log(scareMe.property); // undefined + + \ No newline at end of file diff --git a/function-patterns/self-overwrite.html b/function-patterns/self-overwrite.html index 6feb6f7..a27d118 100644 --- a/function-patterns/self-overwrite.html +++ b/function-patterns/self-overwrite.html @@ -1,21 +1,21 @@ - -JavaScript Patterns - - - - - + function next() { + var count = 1; + next = function () { + return ++count; + }; + return count; + } + console.log(next()); // 1 + console.log(next()); // 2 + + \ No newline at end of file diff --git a/general-patterns/access-to-global-object.html b/general-patterns/access-to-global-object.html index e7a8652..4c97a9b 100644 --- a/general-patterns/access-to-global-object.html +++ b/general-patterns/access-to-global-object.html @@ -1,26 +1,26 @@  - -JavaScript Patterns - - - - - + // References + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ + + \ No newline at end of file diff --git a/general-patterns/avoiding-eval.html b/general-patterns/avoiding-eval.html index b23133f..60b513c 100644 --- a/general-patterns/avoiding-eval.html +++ b/general-patterns/avoiding-eval.html @@ -1,43 +1,43 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/general-patterns/avoiding-implied-typecasting.html b/general-patterns/avoiding-implied-typecasting.html index 4eec421..03d87c9 100644 --- a/general-patterns/avoiding-implied-typecasting.html +++ b/general-patterns/avoiding-implied-typecasting.html @@ -1,44 +1,44 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/general-patterns/built-in-prototypes.html b/general-patterns/built-in-prototypes.html index 6411945..c01f6fe 100644 --- a/general-patterns/built-in-prototypes.html +++ b/general-patterns/built-in-prototypes.html @@ -1,32 +1,32 @@  - -JavaScript Patterns - - - - - + // References + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ + + \ No newline at end of file diff --git a/general-patterns/conditionals.html b/general-patterns/conditionals.html index f327e4a..ea448cf 100644 --- a/general-patterns/conditionals.html +++ b/general-patterns/conditionals.html @@ -1,118 +1,121 @@  - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/general-patterns/for-in-loops.html b/general-patterns/for-in-loops.html index 272e2f0..3aa372f 100644 --- a/general-patterns/for-in-loops.html +++ b/general-patterns/for-in-loops.html @@ -1,80 +1,81 @@  - -JavaScript Patterns - - - - - + + // References + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ + + \ No newline at end of file diff --git a/general-patterns/for-loops.html b/general-patterns/for-loops.html index c69b775..161ac47 100644 --- a/general-patterns/for-loops.html +++ b/general-patterns/for-loops.html @@ -1,64 +1,64 @@  - -JavaScript Patterns - - - - - + // preferred 2 + var myarray = [], + i = myarray.length; + while (i--) { + // do something with myarray[i] + } + + + // References + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ + + \ No newline at end of file diff --git a/general-patterns/function-declarations.html b/general-patterns/function-declarations.html index db39848..c0953c6 100644 --- a/general-patterns/function-declarations.html +++ b/general-patterns/function-declarations.html @@ -1,30 +1,32 @@ - -JavaScript Patterns - - - - - + // References + // http://ejohn.org/blog/javascript-as-a-first-language/ + + \ No newline at end of file diff --git a/general-patterns/globals.html b/general-patterns/globals.html index 5adae1a..0b439e5 100644 --- a/general-patterns/globals.html +++ b/general-patterns/globals.html @@ -1,50 +1,50 @@ - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/general-patterns/hoisting.html b/general-patterns/hoisting.html index 039c41a..8fc997e 100644 --- a/general-patterns/hoisting.html +++ b/general-patterns/hoisting.html @@ -1,37 +1,37 @@ - -JavaScript Patterns - - - - - + // References + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ + + \ No newline at end of file diff --git a/general-patterns/minimizing-globals.html b/general-patterns/minimizing-globals.html index 25a89cc..dd652d3 100644 --- a/general-patterns/minimizing-globals.html +++ b/general-patterns/minimizing-globals.html @@ -1,23 +1,23 @@ - -JavaScript Patterns - - - - - + // References + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ + + \ No newline at end of file diff --git a/general-patterns/parseint.html b/general-patterns/parseint.html index 2ba9582..e29ebe2 100644 --- a/general-patterns/parseint.html +++ b/general-patterns/parseint.html @@ -1,36 +1,36 @@ - -JavaScript Patterns - - - - - + // References + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ + + \ No newline at end of file diff --git a/general-patterns/single-var-pattern.html b/general-patterns/single-var-pattern.html index 602e767..518a785 100644 --- a/general-patterns/single-var-pattern.html +++ b/general-patterns/single-var-pattern.html @@ -1,41 +1,41 @@ - -JavaScript Patterns - - - - - + function updateElement() { + var el = document.getElementById("result"), + style = el.style; + // do something with el and style... + } + + // References + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ + + \ No newline at end of file diff --git a/general-patterns/switch-pattern.html b/general-patterns/switch-pattern.html index de99432..32b3e55 100644 --- a/general-patterns/switch-pattern.html +++ b/general-patterns/switch-pattern.html @@ -1,40 +1,40 @@ - -JavaScript Patterns - - - - - + // References + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ + + \ No newline at end of file diff --git a/jquery-patterns/append.html b/jquery-patterns/append.html index 691681e..8f71ae1 100644 --- a/jquery-patterns/append.html +++ b/jquery-patterns/append.html @@ -1,42 +1,42 @@  - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/cache-selector.html b/jquery-patterns/cache-selector.html index ee1db1d..fd1b35d 100644 --- a/jquery-patterns/cache-selector.html +++ b/jquery-patterns/cache-selector.html @@ -1,30 +1,30 @@  - -JavaScript Patterns - - - - - + // References + // http://ejohn.org/blog/learning-from-twitter/ + + \ No newline at end of file diff --git a/jquery-patterns/context-and-find.html b/jquery-patterns/context-and-find.html index dcf873d..66c9893 100644 --- a/jquery-patterns/context-and-find.html +++ b/jquery-patterns/context-and-find.html @@ -1,33 +1,33 @@ - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/data.html b/jquery-patterns/data.html index e0982c1..b951c65 100644 --- a/jquery-patterns/data.html +++ b/jquery-patterns/data.html @@ -1,25 +1,25 @@ - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/decending-from-id.html b/jquery-patterns/decending-from-id.html index ac49259..8e93ed5 100644 --- a/jquery-patterns/decending-from-id.html +++ b/jquery-patterns/decending-from-id.html @@ -1,29 +1,29 @@ - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/detach.html b/jquery-patterns/detach.html index dab1027..870cc52 100644 --- a/jquery-patterns/detach.html +++ b/jquery-patterns/detach.html @@ -1,25 +1,25 @@ - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/event-delegation.html b/jquery-patterns/event-delegation.html index 6273396..30f164e 100644 --- a/jquery-patterns/event-delegation.html +++ b/jquery-patterns/event-delegation.html @@ -1,25 +1,25 @@ - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/left-and-right.html b/jquery-patterns/left-and-right.html index 59f702e..13dc530 100644 --- a/jquery-patterns/left-and-right.html +++ b/jquery-patterns/left-and-right.html @@ -1,25 +1,25 @@ - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/requery.html b/jquery-patterns/requery.html index cb20112..566fe8e 100644 --- a/jquery-patterns/requery.html +++ b/jquery-patterns/requery.html @@ -1,31 +1,33 @@ - -JavaScript Patterns - - - - - + + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/specific-when-needed.html b/jquery-patterns/specific-when-needed.html index ae933e0..2a93509 100644 --- a/jquery-patterns/specific-when-needed.html +++ b/jquery-patterns/specific-when-needed.html @@ -1,25 +1,25 @@ - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/universal-selector.html b/jquery-patterns/universal-selector.html index be7653a..2b915b7 100644 --- a/jquery-patterns/universal-selector.html +++ b/jquery-patterns/universal-selector.html @@ -1,34 +1,34 @@ - -JavaScript Patterns - - - - - + // References + // http://paulirish.com/2009/perf/ + + \ No newline at end of file diff --git a/jquery-patterns/window-scroll-event.html b/jquery-patterns/window-scroll-event.html index 7d4be13..189ea92 100644 --- a/jquery-patterns/window-scroll-event.html +++ b/jquery-patterns/window-scroll-event.html @@ -1,60 +1,61 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/literals-and-constructors/array-literal.html b/literals-and-constructors/array-literal.html index 4a37d43..1ae6ff8 100644 --- a/literals-and-constructors/array-literal.html +++ b/literals-and-constructors/array-literal.html @@ -1,25 +1,25 @@ - -JavaScript Patterns - - - - - + // References + // http://shop.oreilly.com/product/9780596806767.do + + \ No newline at end of file diff --git a/literals-and-constructors/enforcing-new.html b/literals-and-constructors/enforcing-new.html index 7638ce7..1bace10 100644 --- a/literals-and-constructors/enforcing-new.html +++ b/literals-and-constructors/enforcing-new.html @@ -1,55 +1,55 @@ - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/literals-and-constructors/json.html b/literals-and-constructors/json.html index ca8b8e5..40a3e5f 100644 --- a/literals-and-constructors/json.html +++ b/literals-and-constructors/json.html @@ -1,30 +1,30 @@ - -JavaScript Patterns - - - - - + // References + // http://shop.oreilly.com/product/9780596806767.do + + \ No newline at end of file diff --git a/literals-and-constructors/object-literal.html b/literals-and-constructors/object-literal.html index c47c071..c2eb713 100644 --- a/literals-and-constructors/object-literal.html +++ b/literals-and-constructors/object-literal.html @@ -1,26 +1,26 @@ - -JavaScript Patterns - - - - - + // References + // http://shop.oreilly.com/product/9780596806767.do + + \ No newline at end of file diff --git a/literals-and-constructors/primitive-wrappers.html b/literals-and-constructors/primitive-wrappers.html index 7c68277..9147885 100644 --- a/literals-and-constructors/primitive-wrappers.html +++ b/literals-and-constructors/primitive-wrappers.html @@ -1,55 +1,55 @@ - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/literals-and-constructors/regular-expression-literal.html b/literals-and-constructors/regular-expression-literal.html index 85887be..9fe8d6a 100644 --- a/literals-and-constructors/regular-expression-literal.html +++ b/literals-and-constructors/regular-expression-literal.html @@ -1,25 +1,25 @@ - -JavaScript Patterns - - - - - + // References + // http://shop.oreilly.com/product/9780596806767.do + + \ No newline at end of file diff --git a/object-creation-patterns/chaining.html b/object-creation-patterns/chaining.html index d0d8472..b9e501c 100644 --- a/object-creation-patterns/chaining.html +++ b/object-creation-patterns/chaining.html @@ -1,37 +1,37 @@  - -JavaScript Patterns - - - - - + // as opposed to calling them one by one + // obj.increment(); + // obj.add(3); + // obj.shout(); + + \ No newline at end of file diff --git a/object-creation-patterns/declaring-dependencies.html b/object-creation-patterns/declaring-dependencies.html index 8035bff..9793b5a 100644 --- a/object-creation-patterns/declaring-dependencies.html +++ b/object-creation-patterns/declaring-dependencies.html @@ -1,23 +1,23 @@  - -JavaScript Patterns - - - - - + var myFunction = function () { + // dependencies + var event = YAHOO.util.Event, + dom = YAHOO.util.dom; + + // use event and dom variables + // for the rest of the function... + }; + + \ No newline at end of file diff --git a/object-creation-patterns/module.html b/object-creation-patterns/module.html index 40c0b5c..9bb8623 100644 --- a/object-creation-patterns/module.html +++ b/object-creation-patterns/module.html @@ -1,126 +1,126 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/object-creation-patterns/namespace.html b/object-creation-patterns/namespace.html index 0a39725..5ff39ab 100644 --- a/object-creation-patterns/namespace.html +++ b/object-creation-patterns/namespace.html @@ -1,53 +1,53 @@  - -JavaScript Patterns - - - - - + // assign returned value to a local var + var module2 = MYAPP.namespace('MYAPP.modules.module2'); + console.log(module2 === MYAPP.modules.module2); // true + + // skip initial `MYAPP` + MYAPP.namespace('modules.module51'); + + // long namespace + MYAPP.namespace('once.upon.a.time.there.was.this.long.nested.property'); + + \ No newline at end of file diff --git a/object-creation-patterns/object-constants.html b/object-creation-patterns/object-constants.html index 0e08168..c196910 100644 --- a/object-creation-patterns/object-constants.html +++ b/object-creation-patterns/object-constants.html @@ -1,61 +1,61 @@  - -JavaScript Patterns - - - - - + // is the value still intact? + console.log(constant.get("maxwidth")); // 480 + + \ No newline at end of file diff --git a/object-creation-patterns/private-properties-and-methods.html b/object-creation-patterns/private-properties-and-methods.html index eb8d773..93da109 100644 --- a/object-creation-patterns/private-properties-and-methods.html +++ b/object-creation-patterns/private-properties-and-methods.html @@ -1,45 +1,45 @@  - -JavaScript Patterns - - - - - + var myobj; // this will be the object + (function () { + // private members + var name = "my, oh my"; + + // implement the public part + // note -- no `var` + myobj = { + // priviledged method + getName:function () { + return name; + } + }; + }()); + + \ No newline at end of file diff --git a/object-creation-patterns/revelation.html b/object-creation-patterns/revelation.html index 21391ab..9e5febe 100644 --- a/object-creation-patterns/revelation.html +++ b/object-creation-patterns/revelation.html @@ -1,50 +1,51 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/object-creation-patterns/sandbox.html b/object-creation-patterns/sandbox.html index 3200272..22adfed 100644 --- a/object-creation-patterns/sandbox.html +++ b/object-creation-patterns/sandbox.html @@ -1,96 +1,102 @@  - -JavaScript Patterns - - - - - + Sandbox.modules.dom = function (box) { + box.getElement = function () { + }; + box.getStyle = function () { + }; + box.foo = "bar"; + }; + + Sandbox.modules.event = function (box) { + // access to the Sandbox prototype if needed: + // box.constructor.prototype.m = "mmm"; + box.attachEvent = function () { + }; + box.dettachEvent = function () { + }; + }; + + Sandbox.modules.ajax = function (box) { + box.makeRequest = function () { + }; + box.getResponse = function () { + }; + }; + + + // how to use + Sandbox(['ajax', 'event'], function (box) { + // console.log(box); + }); + + Sandbox('ajax', 'dom', function (box) { + // console.log(box); + }); + + Sandbox('*', function (box) { + // console.log(box); + }); + + \ No newline at end of file diff --git a/object-creation-patterns/static-members.html b/object-creation-patterns/static-members.html index e46cd39..b924eab 100644 --- a/object-creation-patterns/static-members.html +++ b/object-creation-patterns/static-members.html @@ -1,125 +1,126 @@  - -JavaScript Patterns - - - - - + + JavaScript Patterns + + + + + \ No newline at end of file diff --git a/object-creation-patterns/sugar-method.html b/object-creation-patterns/sugar-method.html index 0ae1a16..750e6bf 100644 --- a/object-creation-patterns/sugar-method.html +++ b/object-creation-patterns/sugar-method.html @@ -1,36 +1,37 @@  - -JavaScript Patterns - - - - - + var a = new Person('Adam'); + console.log(a.getName()); // 'Adam' + console.log(a.setName('Eve').getName()); // 'Eve' + + \ No newline at end of file