Created
August 21, 2013 00:27
-
-
Save EyePulp/6289059 to your computer and use it in GitHub Desktop.
require.js module example
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
require(['some_module'], // import your module | |
function(mm){ // give it a local reference | |
var MyInstance = new mm({'yo':'ho ho'}); // instantiate it with a value | |
MyInstance.bar(); // run some functions off of it | |
} | |
); |
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
define(['jquery','knockout','lodash'], // define whatever imported modules you need for your module | |
function($,ko,_) { // assign the imported modules to variable references | |
return function(foo){ // return the module you're creating | |
var self = this; | |
self.foo = foo; | |
self.bar = function(){ | |
console.log(self.foo); | |
}; | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment