Javascript function in external file is undefined when declared in a certain way
- by Obay
myfunc() runs successfully when called from within the same js file. but it is undefined (Firebug) when called from an HTML page:
JS file:
$(function() {
myfunc() {
alert('inside myfunc');
}
alert('outside myfunc');
myfunc(); //this successfully runs myfunc()
});
HTML:
<script>
$(function() {
myfunc(); //this doesn't run myfunc(). It's undefined
});
</script>
But when I change myfunc() declaration to:
myfunc = function () { ... }
It's no longer undefined, and runs successfully.
Sorry for this very noob question, but what just happened? Why did it work when I changed the way I declared the function?