Given the function object:
var foo = function foo() {
return "My methods are bar and baz";
};
foo.bar = function () {return "ok";};
foo.prototype.baz = function () {return "ok";};
If foo.bar() or foo.baz() are called, they respond with ok. However, if I try foo.wrong(), I get an error.
Is there a way for the foo function object to respond with "Invalid method called"? In other words can I see what methods are being called within the foo function object to make sure they are valid (exist)?
For example, since javascript searches the prototype chain for valid functions, is there a way to hook into that search and respond with a function of my own if the search fails (maybe a function I added to the prototype of foo to handle invalid methods)?
I would like to test for this situation within the foo function itself and not externaly every time I attempt to call a method of the foo function object.
Also, please stay within strict mode guidelines.