I've been grappling with understanding why this specific line in my code is throwing an error that says 'undefined is not a function'. Here is the associated Plunker.
// This line shows the function to be invoked
console.log((compileStrategies[tAttr.bsFormItem] || noop))
// This line confirms that the bitwise selection results in a function
console.log(angular.isFunction(compileStrategies[tAttr.bsFormItem] || noop))
// Invoking with context leads to 'undefined is not a function'
(compileStrategies[tAttr.bsFormItem] || noop).apply(this, arguments)
I'm puzzled as to why this error occurs even though the bitwise selection clearly resolves to a function. I understand that I could check if
compileStrategies[tAttr.bsFormItem]
is defined before invoking it, but this issue is confounding me. Any insight into this mystery would be greatly appreciated.
Update:
A strange observation is that when the invocation is assigned to a variable or returned, the 'undefined is not a function' error no longer appears.
For example:
var fn = (compileStrategies[tAttr.bsFormItem] || noop).apply(this, arguments)
or
return (compileStrategies[tAttr.bsFormItem] || noop).apply(this, arguments)