I'd like to get an error message when I misspell a variable name or an object property. Strict mode helps with local variables but what if I read a property? e.g.
var vector = {x: 2, y: 3}
var length = Math.sqrt(vector.x*vector.c + vector.y*vector.y)
length will be NaN
. I don't want to get difficult to find bugs in my code just because of a typo. What's the best way to deal with that? I could add a get function to the prototype of Object and then write e.g. vector.get("x")
instead of vector.x
. But I want the undefined checks to be done only in the debugging phase and automatically removed in the finished code.