|
| 1 | +# embeddable-modular-programming-example-for-Javascript |
| 2 | + |
| 3 | + |
| 4 | +A trick I learned from working with CHATGPT, to solve an interesting problem I had. |
| 5 | + |
| 6 | +How do we create modules of javascript, thats embeddable across the web, in one copy paste code, like you can do with google sites? |
| 7 | + |
| 8 | + |
| 9 | +Many programmers use import and export, and multiple files, but I wanted to have it all one copy and paste, and have it leggible. |
| 10 | + |
| 11 | + |
| 12 | +How this trick works is, you create your modules with the script tag, then you give them Id's to be called as objects. |
| 13 | + |
| 14 | + |
| 15 | +Modules are just individual <scripts> in seperate files. The difference between this and regualar module programming of javascript is: |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +It has to be layered in a specific order, like you do within an algorithm. |
| 20 | + |
| 21 | +This is due to how the DOM loads things in HTML. |
| 22 | + |
| 23 | +Its an HTML file, not a javascript one. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +With this trick, you can create individual callable scripts as objects, that can be further troubleshot and debugged, |
| 28 | + |
| 29 | +all embeddable. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +To check if it works, run the file, which is a blank white screen, and hit inspect to read the console.log to see the sum equal |
| 35 | + |
| 36 | +4 |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +Two scripts interacting and calling each other, from two seperate tags in the same html file. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +I may provide more complex examples later. |
0 commit comments