Skip to content

Instantly share code, notes, and snippets.

View toddpi314's full-sized avatar
💻
Movies, Music & Microcode

Todd Morrison toddpi314

💻
Movies, Music & Microcode
View GitHub Profile
@toddpi314
toddpi314 / closure_leak.js
Created June 5, 2012 00:45
Closure Pinning Memory Leak
// 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
@toddpi314
toddpi314 / closure_leak_fixed_1.js
Created June 5, 2012 01:23
Closure Pinning Memory Leak - Fixed 1
// 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();
});
}
@toddpi314
toddpi314 / closure_leak_fixed_2.js
Created June 5, 2012 01:36
Closure Pinning Memory Leak - Fixed 2
// 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() {
@toddpi314
toddpi314 / Singleton_Pattern.js
Created June 5, 2012 14:12
Singleton Pattern
var Singleton = (function () {
var instantiated;
function init() {
// singleton
return {
publicMethod: function () {
// Do some Work
@toddpi314
toddpi314 / Revealing_Module_Pattern_1
Created June 5, 2012 14:31
Revealing_Module_Pattern_1
var myRevealingModule = (function () {
var name, age;
name = "John Smith";
age = 40;
function updatePerson(){
name = "John Smith Updated";
}
@toddpi314
toddpi314 / MooTools_Class_ManagerSample.js
Created June 5, 2012 14:51
MooTools_Class_ManagerSample
var CoreView = new Class({
isLoaded: false,
initialize: function() {},
load: function(successCallback, failureCallback) {
this.isLoaded = true;
// do some work
if (successCallback != null) {
successCallback();
}
@toddpi314
toddpi314 / MooTools_Class_ManagerSample_Extension.js
Created June 5, 2012 15:04
MooTools_Class_ManagerSample_Extension
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);
@toddpi314
toddpi314 / MooTools_Class_ManagerSample_Instancing.js
Created June 5, 2012 15:17
MooTools_Class_ManagerSample_Instancing
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');
});
@toddpi314
toddpi314 / MooTools_Class_ManagerSample_Usage.js
Created June 5, 2012 15:26
MooTools_Class_ManagerSample_Usage
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();
}
@toddpi314
toddpi314 / MooTools_Class_ManagerSample_Cleanup.js
Created June 5, 2012 15:29
MooTools_Class_ManagerSample_Cleanup
// delete the instances
if(myWizardViewInstance != null)
{
delete myWizardViewInstance;
myWizardViewInstance = null;
}
if(myIntroductionViewInstance != null)
{
delete myIntroductionViewInstance;