gecko-dev/js/rhino/docs/examples.html

90 строки
4.3 KiB
HTML

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]">
<title>Rhino Examples</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h1>
Rhino Examples</h1></center>
Examples have been provided that show how to control the JavaScript engine
and to implement scriptable host objects. All the examples are in the cvs
tree at <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/">mozilla/js/rhino/examples</a></tt>.
<br>&nbsp;
<h2>
Sample Scripts</h2>
The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/unique.js">unique.js</a></tt>
script allows printing unique lines from a file.
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/liveConnect.js">liveConnect.js</a></tt>
script shows a sample usage of LiveConnect (Java-to-JavaScript connectivity).
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/jsdoc.js">jsdoc.js</a></tt>
script is a JavaScript analog to Java's <tt>javadoc</tt>. It makes heavy
use of regular expressions.
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/checkParam.js">checkParam.js</a></tt>
script is a useful tool to check that <tt>@param</tt> tags in Java documentation
comments match the parameters in the corresponding Java method.
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/enum.js">enum.js</a></tt>
script is a good example of using a JavaAdapter to implement a Java interface
using a JavaScript object.
<p>The <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/NervousText.js">NervousText.js</a>
script is a JavaScript implementation of the famous NervousText applet
using JavaScript compiled to Java classes using <a href="jsc.html">jsc</a>.
It can be run in the HTML page <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/NervousText.html">NervousText.html</a>.
<br>&nbsp;
<h2>
Controlling the JavaScript Engine</h2>
<h4>
The RunScript class</h4>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript.java">RunScript.java</a></tt>
is a simple program that executes a script from the command line.
<h4>
The Control class</h4>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Control.java">Control.java</a></tt>
is a program that executes a simple script and then manipulates the result.
<h4>
JavaScript Shell</h4>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Shell.java">Shell.java</a></tt>
is a program that executes JavaScript programs; it is a simplified version
of the shell in the <tt>tools</tt> package. The programs may be specified
as files on the command line or by typing interactively while the shell
is running.
<h4>
<b>Multithreaded Script Execution</b></h4>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/DynamicScopes.java">DynamicScopes.java</a></tt>
is a program that creates a single global scope object and then shares
it across multiple threads. Sharing the global scope allows both information
to be shared across threads, and amortizes the cost of Context.initStandardObjects
by only performing that expensive operation once.
<br>&nbsp;
<h2>
Implementing Host Objects</h2>
First check out the <a href="http://www.mozilla.org/rhino/tutorial.html">tutorial</a>
if you haven't already.
<h4>
The Foo class - Extending ScriptableObject</h4>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Foo.java">Foo.java</a></tt>
is a simple JavaScript host object that includes a property with an associated
action and a variable argument method.
<br>&nbsp;
<h4>
The Matrix class - Implementing Scriptable</h4>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Matrix.java">Matrix.java</a></tt>
provides a simple multidimensional array by implementing the Scriptable
interface.
<br>&nbsp;
<h4>
The File class - An advanced example</h4>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/File.java">File.java</a></tt>
extends ScriptableObject to provide a means of reading and writing files
from JavaScript. A more involved example of host object definition.
<p>
<hr WIDTH="100%">
<br><a href="index.html">back to top</a>
</body>
</html>