鉴于以下代码,有没有办法让我检测通过调用fn()返回的闭包是否包含给定的方法而不必执行fn本身?
// Example function which provides a closure with an 'execute' method.
var fn = function () {
return {
execute: function () {
}
};
};
// Test for the presense of an 'execute' method in the function's closure
if ("function" === typeof fn().execute) {
print("supplied function includes an execute method");
} else {
print("supplied function does not include an execute method");
}
谢谢!
答案 0 :(得分:1)
不,没有。没有它就无法检查返回值。 - Felix Kling