如果我有如下功能:
function catchUndefinedFunctionCall( name, arguments )
{
alert( name + ' is not defined' );
}
Run Code Online (Sandbox Code Playgroud)
而且我做的事情很傻
foo( 'bar' );
Run Code Online (Sandbox Code Playgroud)
当没有定义foo时,是否有某些方法可以调用我的catch函数,名称为'foo',参数是包含'bar'的数组?
var tr={};
tr.SomeThing='SomeThingElse';
console.log(tr.SomeThing); // SomeThingElse
console.log(tr.Other); // undefined
tr.get=function(what){
if (tr.hasOwnProperty(what)) return tr[what];
else return what;
};
tr.get('SomeThing') // SomeThingElse
tr.get('Other') // Other
Run Code Online (Sandbox Code Playgroud)
有没有办法让tr.Other或tr ['Other']和对象的所有其他未定义属性返回其名称而不是未定义?