Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use typeof and try catch : (window[fctName] doesn't always works because you aren't always in the window "scope" or you need to test object members (or simulated namespace etc.))</p> <pre><code>function isFunction(fctName) { try { return typeof(eval(fctName)) === "function"; } catch (err) { return false; } } function isFunction2(fctName) { return typeof(window[fctName]) === "function"; } var myFunc1 = function () {}; function myFunc2() {}; var aString = "hello world!"; console.log(myFunc1); // function () {} console.log(myFunc2); // function myFunc2() {} // Can't work : Exception throw // console.log(myFunc3); console.log(window['myFunc1']); // function () {} console.log(window['myFunc2']); // function myFunc2() {} console.log(window['myFunc3']); // undefined console.log(isFunction("myFunc1")); // true console.log(isFunction("myFunc2")); // true console.log(isFunction("myFunc3")); // false console.log(isFunction2("myFunc1")); // true console.log(isFunction2("myFunc2")); // true console.log(isFunction2("myFunc3")); // false console.log(isFunction('aString.toLowerCase')); // true console.log(isFunction('aString.toLower')); // false : toLower doesn't exist console.log(isFunction2('aString.toLowerCase')); // false : aString.toLowerCase isn't defined ! (but aString was) console.log(isFunction2('aString.toLower')); // false : same reason than above // So Eval can be usefull </code></pre> <p><a href="http://jsfiddle.net/L6Q9N/2" rel="nofollow">http://jsfiddle.net/L6Q9N/2</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload