puk*_*puk 2 javascript function exists
我知道如何检查是否存在全局上下文的属性.任何变化
if (typeof myFunction != 'undefined'){...}
Run Code Online (Sandbox Code Playgroud)
但如果我不知道该功能的名称怎么办?我认为全球我可以做到这一点
if (typeof this['myFunction'] != 'undefined'){...}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在这样的功能中做到这一点
function load(functionName){
if (typeof GLOBALCONTEX[functionName] != 'undefined'){
GLOBALCONTEX[functionName](arg1 , arg2 , ...);
}
}
Run Code Online (Sandbox Code Playgroud)
而且我不想使用try/catch,因为我听说它很慢.
如果使用浏览器,请替换GLOBALCONTEX为window.例:
function load(functionName){
if (typeof window[functionName] != 'undefined'){
window[functionName](arg1 , arg2 , ...);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5110 次 |
| 最近记录: |