Created
May 23, 2015 18:49
-
-
Save uupaa/04cc5e9e9ee85eb17e45 to your computer and use it in GitHub Desktop.
WebModule idiom v2 base code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function moduleExporter(moduleName, moduleBody) { // http://git.io/WebModule | |
| "use strict"; | |
| var alias = moduleName in GLOBAL ? (moduleName + "_") : moduleName; // switch | |
| var entity = moduleBody(); | |
| if (typeof modules !== "undefined") { | |
| GLOBAL["modules"]["register"](alias, moduleBody, entity["repository"]); | |
| } | |
| if (typeof exports !== "undefined") { | |
| module["exports"] = entity; | |
| } | |
| GLOBAL[alias] = entity; | |
| })("REPOSITORY_NAME", function moduleBody() { | |
| "use strict"; | |
| // --- dependency modules ---------------------------------- | |
| // --- define / local variables ---------------------------- | |
| // --- class / interfaces ---------------------------------- | |
| function REPOSITORY_NAME(value) { // @arg String = "" - comment | |
| //{@dev | |
| //$args(REPOSITORY_NAME, arguments); | |
| //$valid($type(value, "String|omit"), REPOSITORY_NAME, "value"); | |
| //}@dev | |
| this._value = value || ""; | |
| } | |
| REPOSITORY_NAME["repository"] = "https://github.com/GITHUB_USER_NAME/REPOSITORY_NAME.js"; // GitHub repository URL. http://git.io/Help | |
| REPOSITORY_NAME["prototype"] = Object.create(REPOSITORY_NAME, { | |
| "constructor": { "value": REPOSITORY_NAME }, // new REPOSITORY_NAME(value:String = ""):REPOSITORY_NAME | |
| // property accessor | |
| "value": { // REPOSITORY_NAME#value:String | |
| "set": function(v) { this._value = v; }, | |
| "get": function() { return this._value; } | |
| }, | |
| // methods | |
| "concat": { "value": REPOSITORY_NAME_concat }, // REPOSITORY_NAME#concat(a:String):String | |
| "concat$": { "value": REPOSITORY_NAME_concat$ }, // REPOSITORY_NAME#concat$(a:String):this | |
| }); | |
| // This example is the ES6::Class extend syntax, were simulated in ES5::Object.create. | |
| // class SubClass extends REPOSITORY_NAME { ... } | |
| /* | |
| function SubClass() { | |
| REPOSITORY_NAME.apply(this, arguments); | |
| } | |
| SubClass["prototype"] = Object.create(REPOSITORY_NAME.prototype, { | |
| "constructor": { "value": SubClass }, | |
| "concat": { "value": SubClass_concat }, | |
| "concat$": { "value": SubClass_concat$ }, | |
| }); | |
| */ | |
| // --- implements ------------------------------------------ | |
| function REPOSITORY_NAME_concat(a) { // @arg String | |
| // @ret String | |
| return this._value + a; | |
| } | |
| function REPOSITORY_NAME_concat$(a) { // @arg String | |
| // @ret this | |
| this._value += a; | |
| return this; | |
| } | |
| return REPOSITORY_NAME; // return ModuleEntity | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment