In some cases, the this
keyword may not refer to the object I expect it to. (recent example: in an key event, in my XBL)
What's the best approach to avoid this kind of mistake?
For now, I'm using always the $.fn
from jQuery to store my variables, but I'm not sure if it's the best approach.
TypeError is one of the most common errors in JavaScript apps. This error is created when some value doesn't turn out to be of a particular expected type. Some of the common cases when it occurs are: Invoking objects that are not methods.
Grammatical mistakes, such as missing parentheses or unmatched brackets, are the major causes of syntax errors in JavaScript. For example, when you must use conditional statements to address multiple conditions, you may miss providing the parentheses as required, leading to syntax flaws.
Learn how and why this
behaves the way it does, then read the code you're working on.
Don't trust some magic functionality, you might always end up with unexpected results if you don't know/read the code.
There's simply no single awesome solution for this "problem".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With