Skip to content

Instantly share code, notes, and snippets.

@themusicman
Created April 15, 2011 02:00
Show Gist options
  • Save themusicman/920993 to your computer and use it in GitHub Desktop.
Save themusicman/920993 to your computer and use it in GitHub Desktop.
var SITE = {
URL: 'http://google.com',
init: function() {
//bring "this" (SITE object) into scope for the anonymous function passed to the click method.
var self = this;
$('#link').click(function() {
/*
"this" is the "this" of the anonymous function passed to the jQuery click method. Which jQuery assigns the HTML element found
by the #link selector. So, "this" is the link. How then can we get access to the URL proptery in the SITE object?
*/
window.location = self.URL;
// or, since we are treating the SITE object as a singleton we could just do ...
window.location = SITE.URL;
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment