How to check if function exists in JavaScript?

Publicado el: 03 abril 2024
en el canal de: Code Samples
17
0

My code is
function getID( swfID ){
if(navigator.appName.indexOf("Microsoft") != -1){
me = window[swfID];
}else{
me = document[swfID];
}
}

function js_to_as( str ){
me.onChange(str);
}

However, sometimes my onChange does not load. Firebug errors with

me.onChange is not a function

I want to degrade gracefully because this is not the most important feature in my program. typeof gives the same error.
Any suggestions on how to make sure that it exists and then only execute onChange?
(None of the methods below except try catch one work)


En esta página del sitio puede ver el video en línea How to check if function exists in JavaScript? de Duración hora minuto segunda en buena calidad , que subió el usuario Code Samples 03 abril 2024, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 17 veces y le gustó 0 a los espectadores. Disfruta viendo!