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

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -