var testObj = this.getView();
Run Code Online (Sandbox Code Playgroud)
如果testObj callableFunction在我实际尝试调用之前有,那么我如何检查DoJo(或者只是本机JS),如果callableFunction()不存在则会失败?我更喜欢本机DoJo解决方案,因为我需要这个解决方案适用于所有浏览器.
dfs*_*fsq 82
你可以这样称呼它:
testObj.callableFunction && testObj.callableFunction();
Run Code Online (Sandbox Code Playgroud)
或详细说明:
if (typeof testObj.callableFunction == 'function') {
testObj.callableFunction();
}
Run Code Online (Sandbox Code Playgroud)