multipage Example

this example shows two pages, each page asynchronously loads different script files

when in BMW page, it uses bmwCarController, which requires bmwCar

bmwCarController.js

1
2
3
4
5
6
7
8
9
10
var BmwCarController = function() {
this.$id = "bmwCarController";
this.$bmwCar = null;
}
BmwCarController.prototype.run = function() {
this.$bmwCar.run();
}
bearcat.module(BmwCarController, typeof module !== 'undefined' ? module : {});

bmwCar requires bmwEngine and bmwWheel

bmwCar.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var BmwCar = function() {
this.$id = "bmwCar";
this.$bmwEngine = null;
this.$bmwWheel = null;
this.$printUtil = null;
}
BmwCar.prototype.run = function() {
this.$bmwEngine.start();
this.$bmwWheel.run();
var msg = 'bmwCar run...';
console.log(msg);
this.$printUtil.printResult(msg);
}
bearcat.module(BmwCar, typeof module !== 'undefined' ? module : {});

wire them up with bearcat

1
2
3
4
5
6
7
8
9
10
<script src="./lib/bearcat.js"></script>
<script src="./bearcat-bootstrap.js"></script>
<script type="text/javascript">
bearcat.createApp();
bearcat.use(['bmwCarController']);
bearcat.start(function() {
var bmwCarController = bearcat.getBean('bmwCarController');
bmwCarController.run();
});
</script>

the whole source sources can be found on example-multipage