Created
April 21, 2011 10:02
-
-
Save kanonji/934093 to your computer and use it in GitHub Desktop.
Confirmation code to see in what 'this' is.
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
var Try = function(){ | |
this.bar = 'bar'; | |
$(window).bind( "load", { self: this }, this.loaded ); | |
}; | |
Try.prototype = { | |
loaded: function( e ){ | |
console.info('------loaded------'); | |
console.debug(this); | |
this.foo = 'loaded'; | |
$('body').append( $('<ul>').attr('id', 'foo').append($('<li>')).append($('<li>')) ); | |
console.info('---try1---'); | |
e.data.self.try1(); | |
console.info('---try2---'); | |
e.data.self.try2(); | |
$('ul#foo li').each(function(index){ | |
console.debug(index); | |
console.debug(this); | |
console.debug(this.foo); | |
console.debug(this.bar); | |
}); | |
e.data.self.end(); | |
}, | |
init: function(){ | |
console.info('------init------'); | |
console.debug(this); | |
this.foo = 'init'; | |
$('body').append( $('<ul>').attr('id', 'foo').append($('<li>')).append($('<li>')) ); | |
console.info('---try1---'); | |
this.try1(); | |
console.info('---try2---'); | |
this.try2(); | |
this.end(); | |
}, | |
try1: function(){ | |
console.debug(this); | |
console.debug(this.foo); | |
console.debug(this.bar); | |
(function(){ | |
console.debug(this); | |
console.debug(this.foo); | |
console.debug(this.bar); | |
})(); | |
}, | |
try2: function(){ | |
console.debug(this); | |
console.debug(this.foo); | |
console.debug(this.bar); | |
$('ul#foo li').each(function(index){ | |
console.debug(index); | |
console.debug(this); | |
console.debug(this.foo); | |
console.debug(this.bar); | |
}); | |
}, | |
end: function(){ | |
$('body').remove(); | |
} | |
}; | |
var t = new Try(); | |
t.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment