I'm not sure if this is a generic Javascript question: I'm using Appcelerator Titanium so there may be specifics for that platform.
Here is my question: if I add an event listener to an object, will the 'this' keyword in the event listener always point to the object?
Example:
var itemView = Ti.UI.createLabel({
text: 'Dude'
})
itemView.addEventListener('click',function(e){
alert(this.getText())
})
This example works. But maybe that's only because of some benign circumstance that doesn't always apply. My question is: can I rely on it to always work? Is the context for the event handler always the object to which the handler is bound?
Is that a fundamental Javascript law, and does Titanium / Alloy respect it?