I suggest you not to use the typeof variable === 'function', I prefer a function for checking a type, instead of the regular type checking. This approach saved me and my colleagues life many times. For example:
isFunction = function(val) {
return typeof val == 'function' && val.call !== 'undefined';
};
window.foo = function() {
alert("foo called");
};
var func_name = "foo",
/*for testing purpose*/fn = foo; // fn = window[func_name];
if (isFunction(fn)) {
fn();
}
else {
alert(func_name + 'is not defined!');
}
ps: the provided example is not the most perfect version of checking a function type because in IE cross-window calls function appears as object.
onLoadhandler.