I'm creating a method inside of an object literal that relies upon passing the 'this' value of the object literal inside of a self invoking function. A simple example would be:
var obj = {
whoAmI: function(){console.log('I\'m this: ' + this + ' object that exists with it\'s own scope')},
getThis: (function(self){return self})(this)
}
console.log( obj.whoAmI() ); // shows the value of this as the object literal
console.log( obj.getThis ); // logs the window object to the console
I understand that the object literal creates it's own disposable scope, but I'm surprised that I could not pass the value of 'this' from the object literal as a parameter to the anonymous function.