<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;&lt;span&gt;{color:#C00}Red&lt;/span&gt; has two essential JavaScript-wrangling tricks you may want to use: &lt;code&gt;require&lt;/code&gt; statements and backticks (&lt;code&gt;``&lt;/code&gt;).&lt;/p&gt;
&lt;h2&gt;&lt;code&gt;require&lt;/code&gt; Statements&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;{color:#C00}Red&lt;/span&gt; leverages &lt;code&gt;require&lt;/code&gt; statements to keep all your application code in a single &lt;code&gt;.js&lt;/code&gt; output file.  &lt;code&gt;require&lt;/code&gt; statements work by compiling the required library and inserting it at the point of requirement.&lt;/p&gt;
&lt;p&gt;Given the two files &lt;code&gt;test_class.red&lt;/code&gt; and &lt;code&gt;application.red&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;
  # test_class.red
 1| class Test
 2|   def output(str)
 3|     puts str
 4|   end
 5| end

  # application.red
 1| require 'test_class.red'
 2| Test.new.output(&quot;It worked!&quot;)
&lt;/pre&gt;
&lt;p&gt;Running &lt;code&gt;red application&lt;/code&gt; on the command line will produce the file &lt;code&gt;application.js&lt;/code&gt;.  This file will contain the minimum amount of Ruby source JavaScript needed, the compiled JavaScript for &lt;code&gt;test_class.red&lt;/code&gt;, and finally the JavaScript for &lt;code&gt;application.red&lt;/code&gt;.  In this way, &lt;span&gt;{color:#C00}Red&lt;/span&gt; allows you to split the code you write into more easily managed files, and to use other &lt;span&gt;{color:#C00}Red&lt;/span&gt; libraries in your own code, with the worry of adding and ordering multiple &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags in your &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;.&lt;/p&gt;
&lt;h2&gt;Backticks (&lt;code&gt;``&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;If you need to get at a native JavaScript property or have a favorite JavaScript trick you just can&amp;#8217;t give up, &lt;span&gt;{color:#C00}Red&lt;/span&gt; allows you to write JavaScript directly using backticks.&lt;/p&gt;
&lt;pre&gt;
  # example.red
 1| def reverse_output(ary)
 2|   `var i = ary.length`
 3|   `while(i) { console.log(ary[--i]); }`
 3| end
&lt;/pre&gt;</body>
  <created-at type="datetime">2008-10-13T10:48:52-07:00</created-at>
  <id type="integer">66733</id>
  <permalink>two-tricks</permalink>
  <repository-id type="integer">38990</repository-id>
  <title>Two Tricks</title>
  <updated-at type="datetime">2008-10-14T04:53:52-07:00</updated-at>
  <user-id type="integer">19153</user-id>
</wiki>
