chopper draw lion4 chopper draw lion4 - 2 years ago 118
Javascript Question

How do I install underscore.js?

I am trying to install underscore.js so I can use it in my browser, but it seems all installation instructions are meant for servers. How do I use this in my web browser? I know JS has no import or require so I am not sure what to do. Thanks

Answer Source

Please include what browser you are using, but few things come to mind:

  1. Head over to JSFiddle or JSBin or other alternatives, include or select the JS framework you want to use and play with it.
  2. Using JS in a browser means nothing. There's got to be some HTML code involved that could use and understand JS code.

    • Firefox, install addon like Firebug, open a simple page like one of SO or and in the console

      var script = document.createElement("script"); script.src = "http://path/to/underscor.js"; document.body.appendChild(script);

      Then you could start using functions in your JS file.

    • Google Chrome, click F-12, go to Sources tab, click on Content Scripts in left panel, right click to add folder containing your JS files. That should work as well. There is also another sub-tab called snippets in left panel, create a new file and just copy paste entire JS file into it. Alternatively, you could follow the same technique for Firefox. Its Developer Panel is much more advanced and sophisticated.
  3. You can try and look at things like Browserify.

The gist is, you need some kind of HTML to invoke and use JS code. IMHO, tools like JSFiddle are much better at using and testing some JS code and involves less hassle. Or just create a simple HTML file on your system, include a script tag and test it.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download