Created
October 8, 2010 20:00
-
-
Save davidvanvickle/617432 to your computer and use it in GitHub Desktop.
javascript objects
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 ims = (typeof window.ims == 'undefined') ? {} : window.ims; | |
var ims.myClass = function(args) { | |
var myPrivate1 = 'private 1'; | |
var myPrivate2 = 'private 2'; | |
var myPrivateMethod = function() { | |
return myPrivate1; | |
} | |
var myPrivateMethod2 = function() { | |
return "you're gay"; | |
} | |
var changeValues = function(value) { | |
myPrivate1 = myPrivate2 = value; | |
} | |
this.myProtected = 'protected var'; | |
this.protectedChange = function(value) | |
{ | |
changeValues(value); | |
} | |
this.myProtectedMethod = function() { | |
alert(myPrivate2); | |
alert(myPrivateMethod2()); | |
return this.myProtected; | |
} | |
} | |
ims.myClass.prototype.myPublic = function(args) { | |
this.myProtectedMethod(); | |
} | |
ims.myClass.prototype.changeValues = function(value) { | |
this.myProtected = value; | |
this.protectedChange(value); | |
} | |
var something = new ims.myClass(args); | |
something.myPublic(); | |
something.changeValues('something'); | |
something.myProtectedMethod(); | |
soemthing.protectedChange('somethingelse'); | |
ims.eventManager = function() | |
{ | |
var events = []; | |
var messages = []; | |
var self = this; | |
var eventFactory = function(type, callback) { | |
return { | |
type: type, | |
callback: callback, | |
context: self | |
} | |
} | |
this.getEvents = function() { | |
return events; | |
} | |
this.getMessages = function() { | |
return messages; | |
} | |
this.addEvent = function(type, callback) { | |
var event = eventFactory(type, callback); | |
events.push(event); | |
} | |
} | |
ims.eventManager.__instance = null; | |
ims.eventManager.getInstance = function(){ | |
if (ims.eventManager.__instance == null) ims.eventManager.__instance = new ims.eventManager(); | |
return ims.eventManager.__instance; | |
} | |
var listener = { | |
textEvent: function(event) { | |
alert(event.type); | |
alert('did something'); | |
} | |
} | |
var eventManager = ims.eventManager.getInstance(); | |
eventManager.addEvent('text',listener.textEvent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment