Is there a smart way to manage undefined properties and/or identifiers on an object before they result in failure/returning undefined?
Can we intercept access to a non-defined property and address it without resorting to try/catch blocks?
var myObj = {
myVar : 10,
myFunc : function(){console.log('foo')}
}
myObj.myVar;
myObj.myFunc();
var x = "myFunc";
myObj[x];
x = "myOtherFunc";
// Is there a way to handle this gracefully before it crashes?
myObj[x];
I am unable to modify the calling code, but can make changes within myObj as it is a module used by others.