Created
April 29, 2014 13:53
-
-
Save rblalock/11401052 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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