Skip to content

Instantly share code, notes, and snippets.

@zhengjia
Created February 15, 2011 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhengjia/827941 to your computer and use it in GitHub Desktop.
Save zhengjia/827941 to your computer and use it in GitHub Desktop.
// This can be moved to a separate file later so that it's instantiated at the right time
$(document).observe("dom:loaded", function() {
var tagPicker = new TagPicker();
});
function TagPicker(options) {
// to compensate for JS poor 'this' handling
var that = this;
this.bindEvents();
// that.bindEvents(); // both lines are exactly the same
return that;
}
// EVENT BINDINGS
TagPicker.prototype.bindEvents = function() {
var that = this;
var body = $( $$('body')[0] );
Element.observe(body, 'click', function() {
that.actionToPerform(); // you need 'that' in order to reference the object in events
});
};
// Another Method
TagPicker.prototype.actionToPerform = function() {
// in case we need the parent object.
var that = this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment