Expression throws JS error on attempt to invoke non-fn as fn #14072
Description
In expressions, undefined
or null
references are supposed to short-circuit evaluation, resulting in an undefined
value, but no ReferenceError
or TypeError
. Therefore, invoking an expression $ctrl.x()
should not give an error if $ctrl.x
is undefined. Great.
If, however, $ctrl.x = 4
(or any other non-undefined|null|function
value), invoking $ctrl.x()
gives a very hard-to-track Error
: v2.x is not a function
, which leads to the bowels of ASTCompiler.prototype.compile
Is this intentional, or should this bail out with undefined
? Although it ultimately helped me find an issue with my code, it was extremely hard to trace (the offending fn call had a name very commonly used in our project).
See this Plunkr for a demonstration: http://plnkr.co/edit/0OnZCNnaGhrsObJZ6uBU?p=preview
I am using Angular 1.5.0.