Skip to content

Instantly share code, notes, and snippets.

@tecnocrata
Created February 8, 2013 13:03
Show Gist options
  • Select an option

  • Save tecnocrata/4738932 to your computer and use it in GitHub Desktop.

Select an option

Save tecnocrata/4738932 to your computer and use it in GitHub Desktop.
Javascript Singleton with Self-writing Methods/Classes
/*var SocketRouter = function() {
console.log('Socket Router initialization');
SocketRouter = function() {
console.log('But I already did something!');
};
};
var x1 = new SocketRouter();
var x2 = new SocketRouter();
var x3 = new SocketRouter();*/
function socketRouter() {
console.log('Socket Router initialization');
socketRouter = function() {
console.log('But I already did something!');
};
socketRouter.XX= function (){
console.log ('Calling XX');
};
};
var x1 = new socketRouter();
var x2 = new socketRouter();
var x3 = new socketRouter();
socketRouter.XX();
/*var doSomething = function(x) {
console.log('Doing something useful initialization '+x);
doSomething = function() {
console.log('But I already did something!');
};
};
var a1 = new doSomething(1);
var a2 = new doSomething(2);
var a2 = new doSomething(3);*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment