In php I\'m writing the following
In javascript I wish to test if the
You should use strict comparison operator !==
if(typeof myFunction !== 'function'){
window.myFunction = function(){}; // for a global function or
NAMESPACE.myFunction = function(){}; // for a function in NAMESPACE
}
Also try to keep js functions inside namespaces, this way you avoid collisions with other js libraries in the future.
Use a function expression, not a function declaration.
if(typeof myfunction != 'function'){
window.myfunction = function(){};
}
(I'm using window
since your last paragraph suggests you want a global function)