Skip to content

Instantly share code, notes, and snippets.

@rblalock
Created April 29, 2014 13:53
Show Gist options
  • Save rblalock/11401052 to your computer and use it in GitHub Desktop.
Save rblalock/11401052 to your computer and use it in GitHub Desktop.
/**
* Structure of an alloy controller
**/
function Controller() {
var $ = this;
}
module.exports = Controller;
/**
* CommonJS has a global object called "exports". If you put
* it inside the Alloy controller (see below) then it doesn't exists until
* you call the controller, then it will exist OUTSIDE the controller function
* making it static / singleton
*/
function Controller(_args) {
var $ = this;
exports.myThing = _args.something;
}
module.exports = Controller;
/**
* This is essentially the same thing as
*/
exports.myThing;
function Controller(_args) {
var $ = this;
exports.myThing = _args.something;
}
module.exports = Controller;
/**
* now exports.myThing is static and everytime you change it in this controller, it's changed
* for all controller instances. Bad move. Always use $.myThing in an Alloy controller.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment