javascript checking for function and giving output if it exists -


I need a script which checks that the function is on the page and, if it is, this function calls And if not, it calls a different function

This is what I thought:

  if (example function) diffunction (); And other works ();  

You have to be careful to check the names not defined in Javascript. Referring to a name that is not defined will cause an error:

  & gt; If (examplefunction) console.log ('exist'); Else console.log ('???') ReferenceError: Examination Function is not defined  

Examining a name with typeof , however, is Safe, whether that name is defined or not, to check if a variable is defined for a true value, you should use it:

  If (example, example! = 'Undefined' and & amp; amp;; example function) diffunction (); Any other work ();  

Comments

Popular posts from this blog

c++ - C/pp Sockets, recv()/send() works only under gdb -

GO: Serve static pages -

objective c - How to open front/back camera at the same time in iOS developing? -