Skip to content

Instantly share code, notes, and snippets.

@imalberto
Last active December 28, 2015 01:49
Show Gist options
  • Select an option

  • Save imalberto/7423733 to your computer and use it in GitHub Desktop.

Select an option

Save imalberto/7423733 to your computer and use it in GitHub Desktop.
Modules Definitions Examples
// 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`
});
//
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');
(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