Last active
August 29, 2015 14:19
-
-
Save pmachapman/57393813e18b8c7a8ce7 to your computer and use it in GitHub Desktop.
Modular Javascript 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
// The object will be called test | |
var test = (function () { | |
// Use strict mode for JavaScript parsing | |
// The browser uses this | |
"use strict"; | |
// Global Variables - JSLint stuff... | |
/*global $*/ | |
/*global utilities*/ | |
var myPublicVariable; | |
var myPrivateVariable; | |
/** | |
* It is my function | |
* | |
* @param x The parameter! | |
* @param y The second parameter! | |
* @returns The result! | |
*/ | |
function myFunction(x, y) { | |
myPrivateVariable = x + y; | |
return myPrivateVariable; | |
} | |
// Standard jquery can be inside the function | |
$(document).ready(function () { | |
}); | |
// Expose only the functions and variables we want to expose | |
return { | |
myFunction: myFunction, | |
myPublicVariable: myPublicVariable | |
}; | |
})(); | |
// Call the function | |
test.myFunction(1, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment