I'm trying to use some function defined in a file inside a HTML script tag.
Here is the javascript file myfunction.js:
fct = function() {
};
Inside index.html I have:
<script src="./myfunction.js"></script>
<script>
fct.some.property = function() {
}
</script>
It says fct.some is undefined on the console. How to define some inside fct so that I can use it in oter scripts ? I don't want to use any librairies.
I tried the following but it does not work :
fct = function() {
return {
some: {}
}
};
I can't reproduce the error; when I test your code as-is I get
fct.some is undefined
The fix is:
fct.some = {};
fct.some.property = function() {
}
This works fine for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With