Skip to content

Instantly share code, notes, and snippets.

@ryanguill
Created May 16, 2016 13:29
Show Gist options
  • Save ryanguill/a16c35a54a1e11ddc32d01e9274fca93 to your computer and use it in GitHub Desktop.
Save ryanguill/a16c35a54a1e11ddc32d01e9274fca93 to your computer and use it in GitHub Desktop.
/*global _, jQuery */
var APP = APP || {};
//just for testing
APP.dependencyOne = true;
APP.dependencyTwo = true;
APP.player = (function player(dependencyOne, dependencyTwo) {
"use strict";
function make (args) {
args = args || {};
var state = {
team: args.team || "",
name: args.name || "",
};
function getName () {
return state.name;
};
function getTeam () {
return state.team;
};
return {
getName: getName,
getTeam: getTeam
};
};
return {
make: make
};
}(APP.dependencyOne, APP.dependencyTwo)); //this is for dependencies to the module, not instance args
//----------
var p1 = APP.player.make({name: "Player 1", team: "Red Team"}); //instance args go here
console.log(p1.getName());
@ryanguill
Copy link
Author

Id probably write these a bit differently in es6, but we've used this pattern for a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment