Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript notification when accessing an undefined object property

I think Javascript is trying to kill me. Errors that would be caught by a compiler in any statically-typed language including FORTRAN, or turn into a run-time exception in any decent dynamically-typed language are swallowed silently by Javascript, patiently waiting to manifest as a bug elsewhere.

Whenever we write Frontend code (nowadays with Angular), we spend most of our time hunting down mistakes such as writing $scope.result = data.results instead of data.result . While some tools help, it still requires an astonishing amount of work.

Is there a way to cause the Javascript environment (in a browser) to log a warning whenever someone tries to read a non-existing object property? I don't want to change the language's semantics - accessing data.results should still returned undefined, I just want to see a warning on the console saying "Non-existing property accessed, file ... line ...".

like image 572
zmbq Avatar asked Nov 24 '25 08:11

zmbq


1 Answers

This is a duplicate of this question I think : Force JavaScript exception/error when reading an undefined object property?

In short : no satisfying solution for your use case, but if you all use firefox you can use javascript.options.strict set to true to have warning in such cases :)

like image 194
Mijamo Avatar answered Nov 26 '25 20:11

Mijamo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!