Last active
December 28, 2015 01:49
-
-
Save imalberto/7423733 to your computer and use it in GitHub Desktop.
Modules Definitions Examples
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
| // Definition | |
| define('newsModel', [ 'Y.Model', 'Y.Models.DefaultModel'], function (newsModel) { | |
| // create the newsModel object | |
| var factory = function () { | |
| return { | |
| newsModel = Y.Base.create(xxx), | |
| init: function () { } | |
| }; | |
| }; | |
| return factory; | |
| }); | |
| // Usage | |
| require(['newsModel'], function (newsModel) { | |
| // do something with `newsModel` | |
| }); |
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
| // | |
| export function login (user, pwd) { | |
| // code here | |
| }; | |
| // usage | |
| import login from 'login'; | |
| /////////////////////// | |
| // | |
| module 'foo' { | |
| export function A() { } | |
| export function B() { } | |
| } | |
| // usage: | |
| import {A as funcA, B} from 'foo'; | |
| funcA(); B(); | |
| var result = login('x', 'y'); | |
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(root, factory) { | |
| "use strict"; | |
| if (typeof define === "function" && define.amd) { // 1 | |
| define(["login"], factory); | |
| } else if (typeof require === 'function' && require.resolve) { | |
| exports = factory(root.login); | |
| } else { | |
| root.ssc = factory(root.login); // 2 | |
| } | |
| }(this, function(login) { // 3 | |
| "use strict"; | |
| return { | |
| myConstant: 1984, | |
| login: function(userNameValue, userPasswordValue) { | |
| console.log("login for " + userNameValue + " and " + userPasswordValue); | |
| }, | |
| logout: function() { | |
| console.log("logout implementation omitted"); | |
| } | |
| }; | |
| })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment