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
// /javascripts/myapp/ui/fancyslider.js | |
MyApp.ns("MyApp.UI.FancySlider"); | |
MyApp.UI.FancySlider = function() { | |
// ... | |
}; |
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
var MyApp = {}; | |
MyApp.namespace = function() { | |
var ln = arguments.length, i, value, split, x, xln, parts, object; | |
for (i = 0; i < ln; i++) { | |
value = arguments[i]; | |
parts = value.split("."); | |
object = window[parts[0]] = Object(window[parts[0]]); | |
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
// Top level. All reusable code goes somewhere under this main object. | |
var MyApp = {}; | |
// Widgets, and any components that manipulate the DOM. | |
MyApp.UI = {}; | |
// Classes that have reusable logic or calculation. | |
MyApp.Lib = {}; | |
// Custom code that works with external javascript libraries in a reusable way. |
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
$.MyCompany = { | |
Widgets: { | |
data1: 123, | |
func1: function() {} | |
}, | |
HtmlUtils: { | |
data1: 123, | |
func1: function() {} | |
} | |
}; |
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
// /javascripts/mycompany.js | |
var MyCompany = {}; | |
// /javascripts/mycompany/widgets | |
MyCompany.Widgets = {}; | |
MyCompany.Widgets.data1 = 123; | |
MyCompany.Widgets.func1 = function() {}; | |
// /javascripts/mycompany/htmlutils.js | |
MyCompany.HtmlUtils = {}; |
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
var MyCompany = { | |
Widgets: { | |
data1: 123, | |
func1: function() {} | |
}, | |
HtmlUtils: { | |
data1: 123, | |
func1: function() {} | |
} | |
} |
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
MyNamespace.myString; | |
MyNamespace.myInt; | |
MyNamespace.myFunc(); |
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
var MyNamespace = { | |
myString: "someString", | |
myInt: 123, | |
myFunc: function() { | |
return this.myString + " " + this.myInt; | |
} | |
}; |
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
// Less Coupled | |
var CountrySelectClass = function() { | |
var countriesIveBeenTo = { | |
'BE': 'Belgium', | |
'CR': 'Costa Rica', | |
'IT': 'Italy', | |
'US': 'United States of America', | |
'UK': 'United Kingdom' | |
}; |
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
// Heavily Coupled | |
$(function() { | |
$(document.body).append( $('<select id="countries"></select>') ); | |
var countriesIveBeenTo = { | |
'BE': 'Belgium', | |
'CR': 'Costa Rica', | |
'IT': 'Italy', | |
'US': 'United States of America', | |
'UK': 'United Kingdom' |