Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  108] [ 2]  / answers: 1 / hits: 25081  / 13 Years ago, wed, december 21, 2011, 12:00:00

I create functions in Javascript dynamically. Sometimes I need to check if a certain function is actually already created.



I have the name of the function as a string. How can I check whether a function exists based on a given value in a string?


More From » javascript

 Answers
52

You can check whether it's defined in the global scope using;



if (typeof window[strOfFunction] === function) {
// celebrate
//window[strOfFunction](); //To call the function dynamically!
}

[#88441] Tuesday, December 20, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorr

Total Points: 193
Total Questions: 86
Total Answers: 105

Location: Pitcairn Islands
Member since Thu, Jun 24, 2021
3 Years ago
victorr questions
Fri, Nov 13, 20, 00:00, 4 Years ago
Sat, Jul 25, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;