Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created May 12, 2010 18:41
Show Gist options
  • Save ryanflorence/398960 to your computer and use it in GitHub Desktop.
Save ryanflorence/398960 to your computer and use it in GitHub Desktop.
// regular javascript api
var bob = new Person('#dude',{ height: 'short' });
bob.dance('salsa'); // dances the salsa and returns bob
bob.awesome; // returns true
bob.awesome = false; // set the property to something else
// jQuery api
$('#bob').person({ height: 'short' }); // instantiate with options
$('#bob').person(); // returns the class instance since it's already been instantiated
// or in other words, returns and object like `bob` from above
$('#bob').person('dance', 'salsa'); // dance the salsa and returns the jQuery object
// because the class returns `this`, (magic from the mutator)
$('#dude').person('awesome'); // returns true, not the jQuery object because the
// method doesn't return the instance, it returns a value
$('#dude').person('awesome', false); // reassign the property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment