Skip to content

Instantly share code, notes, and snippets.

@shinypb
Created March 30, 2011 23:24
Show Gist options
  • Save shinypb/895515 to your computer and use it in GitHub Desktop.
Save shinypb/895515 to your computer and use it in GitHub Desktop.
/* Assume that this component exists somewhere: */
twttr.klass('twttr.components.Person', function(name, location) {
this.name = name;
this.location = location;
});
/* A few ideas for asyncronous instantiation: */
// 1. Pass variable number of constructor arguments and callback as the last argument
var callback = function(instance) {
console.log('Now I have an instance:', instance);
};
twttr.new('twttr.components.Person', name, location, callback);
// 2. Pass constructor arguments as an array and then a callback
twttr.new('twttr.components.Person', [name, location], callback);
// 3. Callback passed to .ready event
twttr.new('twttr.components.Person', name, location).ready(callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment