Yes, I know how to write programs. How do I *run* them?
Over here I set out the basic question:
http://news.ycombinator.com/item?id=2713391
It seems clear that I've asked the wrong question. Or at least, not asked the question I thought I asked. But certainly not asked the question I wanted to ask.
I know how to program. I have written JavaScript code by following the example syntax and adapting the given examples. Fine.
How do I run the bloody thing?
For Python, I do this:
* Open an editor.
* Write the code
* Save the code as code.py
* Exit the editor
* Type "Python code.py"
* Job done.
I can chmod +x the file and put it on my path and use it as an executable.
I'm looking for the equivalent(s) for JavaScript.
I think that's the question I intended to ask. This information seems sorely lacking in all the "tutorials" I've come across so far.
(
17 comments
| 7 points
| on HN
)
If that's the case create this html file: <html> <head> <script type="text/javascript" src="whatever.js"></script> </head>
<body></body> </html>
And place it in the document root of the web server running on your machine, with your js code in a file called whatever.js alongside it. Then navigate to localhost in your browser, the js will run when the page loads.
This should do you: https://developer.mozilla.org/en/introduction_to_the_javascr...
Edit: Spidermonkey and v8 are packaged up for pretty much any linux distro. Once installed the command to run spidermonkey is `js`, and `d8` for v8. Just add the name of the JS file you wish to run as the first argument.
Done.
Thanks again.
* Save the code as code.js
* Type "node code.js"
You download additional packages/modules with "npm".
* Is it accurate?
* Is it "the best"?
Thx.
Now I just need to work out the DOM details ...
I also know that one can just embed code between <script> tags, and I know that one can reference code in files elsewhere. But that's inefficient for actual learning. I was asking for a more effective setup without having to download, compile and install huge numbers of extras.
Or
If you just want to manipulate others web pages it can be done by pasting into your browser's address bar.
javascript: code here
To make a bookmarklet paste into any bookmark address.