Tags: #amd #lab #js #html
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>
…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");
}
}
};
…and within the lazy-loaded script…
mm.cool_feature = function(){
// code
};
mm.cool_feature();