├── README.md ├── cn └── index.html ├── code-reuse-patterns ├── borrowing-methods.html ├── cp1-default.html ├── cp2-rent-a-constructor.html ├── cp3-rent-and-set-prototype.html ├── cp4-share-the-prototype.html ├── cp5-a-temporary-constructor.html ├── inheritance-by-copying-properties.html ├── klass.html ├── mix-ins.html └── prototypal-inheritance.html ├── css └── style.css ├── design-patterns ├── builder.html ├── chain-of-responsibility.html ├── command.html ├── decorator.html ├── facade.html ├── factory.html ├── iterator.html ├── mediator.html ├── multiton.html ├── observer.html ├── proxy.html ├── singleton.html ├── strategy.html └── visitor.html ├── dom-and-browser └── event-handling.html ├── function-patterns ├── callback.html ├── callbacks-and-scope.html ├── configuration-objects.html ├── currying.html ├── enforcing-new-in-constructors.html ├── function-call.html ├── immediate-functions.html ├── immediate-object-initialization.html ├── init-time-branching.html ├── memoization.html ├── partial-application.html ├── returning-functions.html ├── self-defining-functions.html └── self-overwrite.html ├── general-patterns ├── access-to-global-object.html ├── avoiding-eval.html ├── avoiding-implied-typecasting.html ├── built-in-prototypes.html ├── conditionals.html ├── for-in-loops.html ├── for-loops.html ├── function-declarations.html ├── global-import.html ├── globals.html ├── hoisting.html ├── iife-for-loop.html ├── map-and-filter-by-reduce.html ├── minimizing-globals.html ├── parseint.html ├── shim-sniffing.html ├── single-var-pattern.html └── switch-pattern.html ├── img ├── .gitignore ├── js-patterns-cn.png └── js-patterns.png ├── index.html ├── jquery-patterns ├── append.html ├── cache-selector.html ├── context-and-find.html ├── data.html ├── decending-from-id.html ├── detach.html ├── event-delegation.html ├── left-and-right.html ├── pubsub-callback.html ├── pubsub-custom-events.html ├── pubsub-observable.html ├── pubsub-plugin.html ├── requery.html ├── specific-when-needed.html ├── universal-selector.html └── window-scroll-event.html ├── jquery-plugin-patterns ├── amd-commonjs │ ├── pluginCore.js │ ├── pluginExtension.js │ └── usage.html ├── basic.html ├── best-options.html ├── custom-events.html ├── extend.html ├── highly-configurable-mutable.html ├── jquery-mobile-ui-widget-factory.html ├── lightweight.html ├── namespaced-starter.html ├── prototypal-inheritance.html ├── ui-widget-factory-bridge.html ├── ui-widget-factory-mobile.html ├── ui-widget-factory.html └── ui-widget-requirejs-module.html ├── js ├── libs │ ├── jquery-1.6.4.js │ ├── jquery-1.6.4.min.js │ └── modernizr-2.0.6.min.js ├── plugins.js └── script.js ├── literals-and-constructors ├── array-literal.html ├── enforcing-new.html ├── json.html ├── object-literal.html ├── primitive-wrappers.html └── regular-expression-literal.html └── object-creation-patterns ├── chaining.html ├── declaring-dependencies.html ├── inheritence.html ├── module.html ├── module2.html ├── module3-augmentation.html ├── module4-loose-augmentation.html ├── module5-tight-augmentation.html ├── module6-clone-inheritance.html ├── module7-cross-file.html ├── namespace.html ├── object-constants.html ├── private-properties-and-methods.html ├── revelation.html ├── sandbox.html ├── static-members.html ├── sub-module.html └── sugar-method.html /README.md: -------------------------------------------------------------------------------- 1 | #JavaScript Patterns 2 | 3 | JS Patterns 4 |
5 | Project page at: http://shichuan.github.io/javascript-patterns 6 | 7 | -------------------------------------------------------------------------------- /code-reuse-patterns/borrowing-methods.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /code-reuse-patterns/cp1-default.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 49 | 50 | -------------------------------------------------------------------------------- /code-reuse-patterns/cp2-rent-a-constructor.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 59 | 60 | -------------------------------------------------------------------------------- /code-reuse-patterns/cp3-rent-and-set-prototype.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 44 | 45 | -------------------------------------------------------------------------------- /code-reuse-patterns/cp4-share-the-prototype.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 44 | 45 | -------------------------------------------------------------------------------- /code-reuse-patterns/cp5-a-temporary-constructor.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 76 | 77 | -------------------------------------------------------------------------------- /code-reuse-patterns/inheritance-by-copying-properties.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 77 | 78 | -------------------------------------------------------------------------------- /code-reuse-patterns/klass.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /code-reuse-patterns/mix-ins.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 39 | 40 | -------------------------------------------------------------------------------- /code-reuse-patterns/prototypal-inheritance.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 81 | 82 | -------------------------------------------------------------------------------- /design-patterns/builder.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /design-patterns/chain-of-responsibility.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 65 | 66 | -------------------------------------------------------------------------------- /design-patterns/command.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 43 | 44 | -------------------------------------------------------------------------------- /design-patterns/decorator.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 54 | 55 | -------------------------------------------------------------------------------- /design-patterns/facade.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 26 | 27 | -------------------------------------------------------------------------------- /design-patterns/factory.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 87 | 88 | -------------------------------------------------------------------------------- /design-patterns/iterator.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 57 | 58 | -------------------------------------------------------------------------------- /design-patterns/mediator.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 90 | 91 | -------------------------------------------------------------------------------- /design-patterns/multiton.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 84 | 85 | -------------------------------------------------------------------------------- /design-patterns/observer.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 82 | 83 | -------------------------------------------------------------------------------- /design-patterns/proxy.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 42 | 43 | 44 |

Dave Matthews vids

45 |

Toggle Checked

46 |
    47 |
  1. Gravedigger
  2. 48 |
  3. Save Me
  4. 49 |
  5. Crush
  6. 50 |
  7. Don't Drink The 51 | Water
  8. 52 |
  9. Funny the Way It 53 | Is
  10. 54 |
  11. What Would You Say 55 |
  12. 56 |
57 | 58 | 242 | 243 | -------------------------------------------------------------------------------- /design-patterns/singleton.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /design-patterns/strategy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /design-patterns/visitor.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 91 | 92 | -------------------------------------------------------------------------------- /dom-and-browser/event-handling.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 57 | 58 | -------------------------------------------------------------------------------- /function-patterns/callback.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 47 | 48 | -------------------------------------------------------------------------------- /function-patterns/callbacks-and-scope.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 43 | 44 | -------------------------------------------------------------------------------- /function-patterns/configuration-objects.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 24 | 25 | -------------------------------------------------------------------------------- /function-patterns/currying.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /function-patterns/enforcing-new-in-constructors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 22 | 23 | -------------------------------------------------------------------------------- /function-patterns/function-call.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /function-patterns/immediate-functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /function-patterns/immediate-object-initialization.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 35 | 36 | -------------------------------------------------------------------------------- /function-patterns/init-time-branching.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /function-patterns/memoization.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 84 | 85 | -------------------------------------------------------------------------------- /function-patterns/partial-application.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 71 | 72 | -------------------------------------------------------------------------------- /function-patterns/returning-functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /function-patterns/self-defining-functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 41 | 42 | -------------------------------------------------------------------------------- /function-patterns/self-overwrite.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 20 | 21 | -------------------------------------------------------------------------------- /general-patterns/access-to-global-object.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /general-patterns/avoiding-eval.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /general-patterns/avoiding-implied-typecasting.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 43 | 44 | -------------------------------------------------------------------------------- /general-patterns/built-in-prototypes.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 31 | 32 | -------------------------------------------------------------------------------- /general-patterns/conditionals.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /general-patterns/for-in-loops.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /general-patterns/for-loops.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 63 | 64 | -------------------------------------------------------------------------------- /general-patterns/function-declarations.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /general-patterns/global-import.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 20 | 21 | -------------------------------------------------------------------------------- /general-patterns/globals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /general-patterns/hoisting.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 41 | 42 | -------------------------------------------------------------------------------- /general-patterns/iife-for-loop.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 39 | 40 | -------------------------------------------------------------------------------- /general-patterns/map-and-filter-by-reduce.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 44 | 45 | -------------------------------------------------------------------------------- /general-patterns/minimizing-globals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /general-patterns/parseint.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /general-patterns/shim-sniffing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /general-patterns/single-var-pattern.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 54 | 55 | -------------------------------------------------------------------------------- /general-patterns/switch-pattern.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /img/.gitignore: -------------------------------------------------------------------------------- 1 | !.gitignore 2 | 3 | -------------------------------------------------------------------------------- /img/js-patterns-cn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuanxshi/javascript-patterns/bff021b5923cd8a5bbe471c16c724e89324969a7/img/js-patterns-cn.png -------------------------------------------------------------------------------- /img/js-patterns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuanxshi/javascript-patterns/bff021b5923cd8a5bbe471c16c724e89324969a7/img/js-patterns.png -------------------------------------------------------------------------------- /jquery-patterns/append.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /jquery-patterns/cache-selector.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /jquery-patterns/context-and-find.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 25 | 26 | -------------------------------------------------------------------------------- /jquery-patterns/data.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 24 | 25 | -------------------------------------------------------------------------------- /jquery-patterns/decending-from-id.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 28 | 29 | -------------------------------------------------------------------------------- /jquery-patterns/detach.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 24 | 25 | -------------------------------------------------------------------------------- /jquery-patterns/event-delegation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 29 | 30 | -------------------------------------------------------------------------------- /jquery-patterns/left-and-right.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 24 | 25 | -------------------------------------------------------------------------------- /jquery-patterns/pubsub-callback.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /jquery-patterns/pubsub-custom-events.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 66 | 67 | -------------------------------------------------------------------------------- /jquery-patterns/pubsub-observable.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | ​ 15 | 41 | 42 | -------------------------------------------------------------------------------- /jquery-patterns/pubsub-plugin.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 75 | 76 | -------------------------------------------------------------------------------- /jquery-patterns/requery.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /jquery-patterns/specific-when-needed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 24 | 25 | -------------------------------------------------------------------------------- /jquery-patterns/universal-selector.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 33 | 34 | -------------------------------------------------------------------------------- /jquery-patterns/window-scroll-event.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 59 | 60 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/amd-commonjs/pluginCore.js: -------------------------------------------------------------------------------- 1 | // Module/Plugin core 2 | // Note: the wrapper code you see around the module is what enables 3 | // us to support multiple module formats and specifications by 4 | // mapping the arguments defined to what a specific format expects 5 | // to be present. Our actual module functionality is defined lower 6 | // down, where a named module and exports are demonstrated. 7 | // 8 | // Note that dependencies can just as easily be declared if required 9 | // and should work as demonstrated earlier with the AMD module examples. 10 | 11 | (function ( name, definition ){ 12 | var theModule = definition(), 13 | // this is considered "safe": 14 | hasDefine = typeof define === 'function' && define.amd, 15 | // hasDefine = typeof define === 'function', 16 | hasExports = typeof module !== 'undefined' && module.exports; 17 | 18 | if ( hasDefine ){ // AMD Module 19 | define(theModule); 20 | } else if ( hasExports ) { // Node.js Module 21 | module.exports = theModule; 22 | } else { // Assign to common namespaces or simply the global object (window) 23 | (this.jQuery || this.ender || this.$ || this)[name] = theModule; 24 | } 25 | })( 'core', function () { 26 | var module = this; 27 | module.plugins = []; 28 | module.highlightColor = "yellow"; 29 | module.errorColor = "red"; 30 | 31 | // define the core module here and return the public API 32 | 33 | // This is the highlight method used by the core highlightAll() 34 | // method and all of the plugins highlighting elements different 35 | // colors 36 | module.highlight = function(el,strColor){ 37 | if(this.jQuery){ 38 | jQuery(el).css('background', strColor); 39 | } 40 | } 41 | return { 42 | highlightAll:function(){ 43 | module.highlight('div', module.highlightColor); 44 | } 45 | }; 46 | 47 | }); -------------------------------------------------------------------------------- /jquery-plugin-patterns/amd-commonjs/pluginExtension.js: -------------------------------------------------------------------------------- 1 | // Extension to module core 2 | 3 | (function ( name, definition ) { 4 | var theModule = definition(), 5 | hasDefine = typeof define === 'function', 6 | hasExports = typeof module !== 'undefined' && module.exports; 7 | 8 | if ( hasDefine ) { // AMD Module 9 | define(theModule); 10 | } else if ( hasExports ) { // Node.js Module 11 | module.exports = theModule; 12 | } else { // Assign to common namespaces or simply the global object (window) 13 | 14 | // account for for flat-file/global module extensions 15 | var obj = null; 16 | var namespaces = name.split("."); 17 | var scope = (this.jQuery || this.ender || this.$ || this); 18 | for (var i = 0; i < namespaces.length; i++) { 19 | var packageName = namespaces[i]; 20 | if (obj && i == namespaces.length - 1) { 21 | obj[packageName] = theModule; 22 | } else if (typeof scope[packageName] === "undefined") { 23 | scope[packageName] = {}; 24 | } 25 | obj = scope[packageName]; 26 | } 27 | 28 | } 29 | })('core.plugin', function () { 30 | 31 | // Define your module here and return the public API. 32 | // This code could be easily adapted with the core to 33 | // allow for methods that overwrite and extend core functionality 34 | // in order to expand the highlight method to do more if you wish. 35 | return { 36 | setGreen: function ( el ) { 37 | highlight(el, 'green'); 38 | }, 39 | setRed: function ( el ) { 40 | highlight(el, errorColor); 41 | } 42 | }; 43 | 44 | }); -------------------------------------------------------------------------------- /jquery-plugin-patterns/amd-commonjs/usage.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 40 | 41 | 45 | 46 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/basic.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 39 | 40 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/best-options.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 61 | 62 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/custom-events.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 68 | 69 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/extend.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 51 | 52 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/highly-configurable-mutable.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 85 | 86 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/jquery-mobile-ui-widget-factory.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 129 | 130 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/lightweight.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 89 | 90 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/namespaced-starter.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 74 | 75 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/prototypal-inheritance.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 88 | 89 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/ui-widget-factory-bridge.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 109 | 110 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/ui-widget-factory-mobile.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 112 | 113 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/ui-widget-factory.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 9 | 107 | 108 | -------------------------------------------------------------------------------- /jquery-plugin-patterns/ui-widget-requirejs-module.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 118 | 119 | -------------------------------------------------------------------------------- /js/plugins.js: -------------------------------------------------------------------------------- 1 | 2 | // usage: log('inside coolFunc', this, arguments); 3 | // paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ 4 | window.log = function(){ 5 | log.history = log.history || []; // store logs to an array for reference 6 | log.history.push(arguments); 7 | if(this.console) { 8 | arguments.callee = arguments.callee.caller; 9 | var newarr = [].slice.call(arguments); 10 | (typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr)); 11 | } 12 | }; 13 | 14 | // make it safe to use console.log always 15 | (function(b){function c(){}for(var d="assert,clear,count,debug,dir,dirxml,error,exception,firebug,group,groupCollapsed,groupEnd,info,log,memoryProfile,memoryProfileEnd,profile,profileEnd,table,time,timeEnd,timeStamp,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try 16 | {console.log();return window.console;}catch(err){return window.console={};}})()); 17 | 18 | 19 | // place any jQuery/helper plugins in here, instead of separate, slower script files. 20 | 21 | -------------------------------------------------------------------------------- /js/script.js: -------------------------------------------------------------------------------- 1 | /* Author: 2 | Shi Chuan 3 | */ 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /literals-and-constructors/array-literal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 24 | 25 | -------------------------------------------------------------------------------- /literals-and-constructors/enforcing-new.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 54 | 55 | -------------------------------------------------------------------------------- /literals-and-constructors/json.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 29 | 30 | -------------------------------------------------------------------------------- /literals-and-constructors/object-literal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 25 | 26 | -------------------------------------------------------------------------------- /literals-and-constructors/primitive-wrappers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 52 | 53 | -------------------------------------------------------------------------------- /literals-and-constructors/regular-expression-literal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 24 | 25 | -------------------------------------------------------------------------------- /object-creation-patterns/chaining.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 36 | 37 | -------------------------------------------------------------------------------- /object-creation-patterns/declaring-dependencies.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 22 | 23 | -------------------------------------------------------------------------------- /object-creation-patterns/inheritence.html: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | JavaScript Patterns - Inheritance 13 | 14 | 15 | 16 | 169 | 170 | 171 |

JAVASCRIP INHERITANCE

172 |

173 | 174 |

175 | 176 | 177 | -------------------------------------------------------------------------------- /object-creation-patterns/module.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 125 | 126 | -------------------------------------------------------------------------------- /object-creation-patterns/module2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 51 | -------------------------------------------------------------------------------- /object-creation-patterns/module3-augmentation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 26 | -------------------------------------------------------------------------------- /object-creation-patterns/module4-loose-augmentation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 26 | -------------------------------------------------------------------------------- /object-creation-patterns/module5-tight-augmentation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 28 | -------------------------------------------------------------------------------- /object-creation-patterns/module6-clone-inheritance.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 36 | -------------------------------------------------------------------------------- /object-creation-patterns/module7-cross-file.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 35 | -------------------------------------------------------------------------------- /object-creation-patterns/namespace.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 52 | 53 | -------------------------------------------------------------------------------- /object-creation-patterns/object-constants.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /object-creation-patterns/private-properties-and-methods.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /object-creation-patterns/revelation.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 50 | 51 | -------------------------------------------------------------------------------- /object-creation-patterns/sandbox.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 101 | 102 | -------------------------------------------------------------------------------- /object-creation-patterns/static-members.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 125 | 126 | -------------------------------------------------------------------------------- /object-creation-patterns/sub-module.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 25 | -------------------------------------------------------------------------------- /object-creation-patterns/sugar-method.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | JavaScript Patterns 5 | 6 | 7 | 8 | 36 | 37 | --------------------------------------------------------------------------------