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
// Component Definition | |
function Component(name) { | |
this.pageName = name; | |
} | |
// Lets decorate the Component instances with | |
// a method that can do some work | |
Component.prototype.onLoaded = function() { | |
// do some fancy work |
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
// On Component.attach, lets subscribe to the | |
// DOM's loaded event and do something on our | |
// self closure context | |
Component.prototype.attach = function() { | |
var self = this; | |
$(document).load(function() { | |
// Self reference removed, not causing closure leak | |
//self.onLoaded(); | |
}); | |
} |
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
// Component Definition | |
function Component(name) { | |
this.pageName = name; | |
this.onLoadedHandler = this.onLoadedHandler.bind(this); | |
} | |
// We can now do our work with the Component | |
// context passed as expected! | |
Component.prototype.onLoadedHandler = 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 Singleton = (function () { | |
var instantiated; | |
function init() { | |
// singleton | |
return { | |
publicMethod: function () { | |
// Do some Work |
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 myRevealingModule = (function () { | |
var name, age; | |
name = "John Smith"; | |
age = 40; | |
function updatePerson(){ | |
name = "John Smith Updated"; | |
} |
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 CoreView = new Class({ | |
isLoaded: false, | |
initialize: function() {}, | |
load: function(successCallback, failureCallback) { | |
this.isLoaded = true; | |
// do some work | |
if (successCallback != null) { | |
successCallback(); | |
} |
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 IntroductionView = new Class({ | |
Extends: CoreView, | |
initialize: function() {}, | |
// Override the Parent Load method and do some custom load tasks | |
load: function(successCallback, failureCallback) { | |
this.parent(function() { | |
// do custom load tasks | |
if (successCallback != null) successCallback(); | |
}, failureCallback); |
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 myIntroductionViewInstance = new IntroductionView(); | |
var myWizardViewInstance = new WizardView(); | |
// Use Async Load Strategy | |
myIntroductionViewInstance.load(function() { | |
myWizardViewInstance.load(function() { | |
console.log('both the myWizardInstance and the myIntroductionInstance loaded'); | |
}, function() { | |
console.log('load failure on the myWizardInstance'); | |
}); |
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
if (myIntroductionViewInstance.getIsLoaded()) { | |
if (myIntroductionViewInstance instanceof CoreView) { | |
console.log('yes, myIntroductionViewInstance is a CoreView'); | |
} | |
if (myIntroductionViewInstance instanceof IntroductionView) { | |
console.log('yes, myIntroductionViewInstance is a IntroductionView'); | |
} | |
myIntroductionViewInstance.showIntroScreen(); | |
} |
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
// delete the instances | |
if(myWizardViewInstance != null) | |
{ | |
delete myWizardViewInstance; | |
myWizardViewInstance = null; | |
} | |
if(myIntroductionViewInstance != null) | |
{ | |
delete myIntroductionViewInstance; |
OlderNewer