This is probably a lame question, but how can you achieve the same thing as require()
(Node.js) in regular JavaScript?
Some help would really be appreciated.
This is probably a lame question, but how can you achieve the same thing as require()
(Node.js) in regular JavaScript?
Some help would really be appreciated.
There are several services that let you do this.
The most popular is Browserify.
Basically, it entails going through the file reading through the syntax tree and converting it to the a style similar to what RequireJS does.
Note that this requires an extra compilation step. (We will eventually get modules in ES6 though so there's that :) )
http://requirejs.org/docs/start.html
A module loader called RequireJS exists for in-browser use without the use of Node.js or Rhino.
To use it download and save the script and include it in your page
The data-main attribute will point to your main script where you can load the rest of your scripts using:
Checkout the documents at http://requirejs.org for more information.