Created
January 18, 2010 14:57
-
-
Save cowboy/280072 to your computer and use it in GitHub Desktop.
jQuery event handler context examples
This file contains hidden or 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
var foo = { | |
context: 'obj', | |
func: function(){ | |
console.log( this.context ); | |
} | |
}; | |
var bar = foo.func; | |
window.context = 'global'; | |
document.context = 'document'; | |
foo.func(); // logs: 'obj' | |
bar(); // logs: 'global' | |
$(function(){ foo.func(); }); // logs: 'obj' | |
$(function(){ bar(); }); // logs: 'global' | |
$( foo.func ); // logs: 'document' | |
$( bar ); // logs: 'document' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment