From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../mozilla/projects/rhino/examples/index.html | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 files/zh-cn/mozilla/projects/rhino/examples/index.html (limited to 'files/zh-cn/mozilla/projects/rhino/examples') diff --git a/files/zh-cn/mozilla/projects/rhino/examples/index.html b/files/zh-cn/mozilla/projects/rhino/examples/index.html new file mode 100644 index 0000000000..087697b94a --- /dev/null +++ b/files/zh-cn/mozilla/projects/rhino/examples/index.html @@ -0,0 +1,35 @@ +--- +title: Rhino Examples +slug: Mozilla/Projects/Rhino/Examples +translation_of: Mozilla/Projects/Rhino/Examples +--- +
+  
+

+

Examples have been provided that show how to control the JavaScript engine and how  to implement scriptable host objects. All the examples are in the git tree at mozilla/js/rhino/examples.

+

Sample Scripts

+

The unique.js script allows printing unique lines from a file.

+

The liveConnect.js script shows a sample usage of LiveConnect (Java-to-JavaScript connectivity).

+

The jsdoc.js script is a JavaScript analog to Java's javadoc. It makes heavy use of regular expressions.

+

The checkParam.js script is a useful tool to check that @param tags in Java documentation comments match the parameters in the corresponding Java method.

+

The enum.js script is a good example of using a JavaAdapter to implement a Java interface using a JavaScript object.

+

The NervousText.js script is a JavaScript implementation of the famous NervousText applet using JavaScript compiled to Java classes using jsc. It can be run in the HTML page NervousText.html.

+

Controlling the JavaScript Engine

+

The RunScript class

+

RunScript.java is a simple program that executes a script from the command line.

+

The Control class

+

Control.java is a program that executes a simple script and then manipulates the result.

+

JavaScript Shell

+

Shell.java is a program that executes JavaScript programs; it is a simplified version of the shell in the tools package. The programs may be specified as files on the command line or by typing interactively while the shell is running.

+

PrimitiveWrapFactory

+

PrimitiveWrapFactory.java is an example of a WrapFactory that can be used to control the wrapping behavior of the Rhino engine on calls to Java methods.

+

Multithreaded Script Execution

+

DynamicScopes.java 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.

+

Implementing Host Objects

+

First check out the tutorial if you haven't already.

+

The Foo class - Extending ScriptableObject

+

Foo.java is a simple JavaScript host object that includes a property with an associated action and a variable argument method.

+

The Matrix class - Implementing Scriptable

+

Matrix.java provides a simple multidimensional array by implementing the Scriptable interface.

+

The File class - An advanced example

+

File.java extends ScriptableObject to provide a means of reading and writing files from JavaScript. A more involved example of host object definition.

-- cgit v1.2.3-54-g00ecf