Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Class_Bar()
- {
- this.panel = null;
- this.init = function ()
- {
- // do some stuff
- this.panel = 20;
- }
- this.apply = function ()
- {
- alert(Bar == this);
- Bar.x();
- this.x();
- }
- this.x = function()
- {
- alert("Some friendly message");
- alert(Bar.panel);
- }
- }
- var Bar = new Class_Bar();
- function Class_Factory()
- {
- this.factories = new Array();
- this.add = function (init, apply)
- {
- this.factories.push({"init":init, "apply":apply});
- }
- this.init = function ()
- {
- for (var i = 0; i < this.factories.length; ++i)
- {
- this.factories[i]["init"]();
- }
- }
- this.apply = function ()
- {
- for (var i = 0; i < this.factories.length; ++i)
- {
- this.factories[i]["apply"]();
- }
- }
- }
- var Factory = new Class_Factory();
- function main()
- {
- // Case 1
- Factory.add(Bar.init, Bar.apply);
- Factory.init();
- Factory.apply();
- // Case 2
- Bar.init();
- Bar.apply();
- }
- main();
Advertisement
Add Comment
Please, Sign In to add comment