Last active
December 16, 2015 23:39
-
-
Save max-mapper/5515039 to your computer and use it in GitHub Desktop.
client side module pattern exmaple
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
// assuming you have $ defined | |
var $ = jqueryblablah | |
// way 1 | |
function addFunctions(global) { | |
function a() {} | |
function b() {} | |
global.a = a | |
global.b = b | |
} | |
// way 2 | |
function addFunctions(global) { | |
global.a = function() {} | |
global.b = function() {} | |
} | |
addFunctions($) | |
// way 3 | |
(function addFunctions(global) { | |
global.a = function() {} | |
global.b = function() {} | |
})($) | |
// lets you do this: | |
$.a() | |
$.b() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment