Created
February 15, 2011 18:13
-
-
Save zhengjia/827941 to your computer and use it in GitHub Desktop.
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
// 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