How to organize javascript on the front-end w/o using server technologies? -
i'm working on front-end javascript project follow characteristics:
- performance not matter
- lots of classes
- client only.
the third point main reason asking question when research how organize javascript on client side answers include server-side library. not have access this. keep classes in 1 folder (maybe sub-folders), main script, , folder 3rd party libraries. haven't found way of doing nicely however.
i've tried in 1 html file this:
<!-- include 3rd party libraya --> <!-- include 3rd party librayb --> <!-- include classa script --> <!-- include classb script --> <!-- include main.js -->
but main.js didn't seem know classes were.
ideally i'd require but, again i've found similar uses server side tech can't use.
here reduced form of tried:
./index.html:
<!doctype html> <html> <head> <title>test</title> <script type="test/javascript" src="./classes/testclass.js"></script> <script type="text/javascript" src="./script.js"></script> </head> <body> </body> </html>
./script.js
var testclassinstance = new testclass("test!"); testclassinstance.bar();
./classes/testclass.js
var testclass = function (foo) { this.foo = foo; }; testclass.prototype.bar = function () { console.log(this.foo); }
the error got was:
script.js:1 uncaught referenceerror: testclass not defined(…)
Comments
Post a Comment