0

Given the following code, is there any way for me to detect if the closure returned by calling fn() contains a given method without having to execute fn itself?

// 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"); }

Thanks!

2
  • 3
    No, there is not. You cannot inspect the return value without having it. Commented Aug 15, 2011 at 12:00
  • 1
    @JonnyReeves, you might find this link useful stackoverflow.com/questions/4849369/… Commented Aug 17, 2011 at 17:42

1 Answer 1

1

No, there is not. You cannot inspect the return value without having it. – Felix Kling

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.