« Back to Index

[JS before AMD]

View original Gist on GitHub

Tags: #amd #lab #js #html

1. HTML.md

Example of how I used to write my code (before I discovered AMD)

For example in my HTML page would be…

<script src="Assets/Scripts/LAB.min.js"></script>
<script>
	$LAB
	.setOptions({ AlwaysPreserveOrder:true, BasePath:"Assets/Scripts/" })
		.script("bootstrap.js").wait(function(){
			mm.init({ cool_feature:true, another_cool_feature:true });
		});
</script>

2. bootstrap.md

…and within bootstrap.js

var mm = {
	init: function (settings) {
		if (settings === undefined) {
			return "this method should be passed an object literal";
		}
		
		if (settings.cool_feature) {
			$LAB.script("/Assets/Scripts/cool_feature.js");
		}
	}
};

3. lazy-loaded.md

…and within the lazy-loaded script…

mm.cool_feature = function(){
	// code
};

mm.cool_feature();