User talk:La Longue Carabine: Difference between revisions

m
m (→‎Analyze and Discuss: Added instructions for putting Spidermonkey code on an HTML page.)
 
(3 intermediate revisions by the same user not shown)
Line 1:
==AnalyzeComments and DiscussDiscussion==
Whatever.
 
 
== To Use Spidermonkey Examples in HTML Documents ==
 
MostMy ofJavaScript mySpidermonkey examples implemented(those inwhich Spidermonkeydo not use <code>readline()</code> or read from files, anyway) can be used on an HTML page as follows:
 
1. Create an HTML page like the one below,
Line 11 ⟶ 10:
2. Paste the Spidermonkey script into it,
 
3. Comment out the callhash-bang to <code>main()</code>line,
 
4. Comment out the call to <code>main()</code>,
4. Load into your browser and enjoy!
 
45. Load into your browser and enjoy!
 
<pre>
Line 22 ⟶ 23:
var printBuf = '';
function putstr() {
var pad = if (arguments.length &gt; 1) printBuf? +=' ' : ';'
for (var i = 0; i &lt; arguments.length; i++) {
printBuf += arguments[i] + pad;
if (arguments.length &gt; 1) printBuf += ' ';
}
}
 
function print() {
var pad = if (arguments[i].length &gt; 1) putstr(? ' '); : ''
for (var i = 0; i &lt; arguments.length; i++) {
putstr(arguments[i] + pad);
if (arguments[i].length &gt; 1) putstr(' ');
}
var d = document.createElement('div');
Line 39 ⟶ 40:
}
 
// Put my code here, but remove the hash-bang and call to main
// #!/usr/bin/env js
// that is usually the last line of the script.
 
// ...
 
//main()