JavaScript手册 
目录
此参考中包含
的内容
轻松上手
简介
操作符
语句
核心
文档
窗口
表单
浏览器
事件和
事件句柄
LiveWire
数据库服务
进程管理服务
实用工具
全局函数
LiveConnect
的Java包
索引
版权
 
【目录】 【上一页】 【下一页】 【索引】

netscape.javascript.JSObject

The public final class JSObject extends Object.

java.lang.Object
   |
   +----netscape.javascript.JSObject
JSObject allows Java to manipulate objects that are defined in JavaScript. Values passed from Java to JavaScript are converted as follows:

Values passed from JavaScript to Java are converted as follows:

This means that all JavaScript values show up as some kind of java.lang.Object in Java. In order to make much use of them, you will have to cast them to the appropriate subclass of Object, as shown in the following示例:

(String) window.getMember("name")
(JSObject) window.getMember("document")

Note If you call a Java method from JavaScript, this conversion happens automatically--you can pass in "int" argument and it works.

方法 and static方法

The netscape.javascript.JSObject class has the following methods:

表 14.1 Methods for the JSObject class

Method 描述
call Calls a JavaScript 方法
eval Evaluates a JavaScript expression
getMember Retrieves a named member of a JavaScript object
getSlot Retrieves an indexed member of a JavaScript object
removeMember Removes a named member of a JavaScript object
setMember Sets a named member of a JavaScript object
setSlot Sets an indexed member of a JavaScript object
toString Converts a JSObject to a string

The netscape.javascript.JSObject class has the following static methods:

表 14.2 Static methods for the JSObject class

Method 描述
getWindow Gets a JSObject for the window containing the given applet

The following sections show the declaration and usage of these methods.

call

Method. Calls a JavaScript method. Equivalent to "this.methodName(args[0], args[1], ...)" in JavaScript.

Declaration

public Object call(String methodName,
   Object args[])

eval

Method. Evaluates a JavaScript expression. The expression is a string of JavaScript source code which will be evaluated in the context given by "this".

Declaration

public Object eval(String s)

getMember

Method. Retrieves a named member of a JavaScript object. Equivalent to "this.name" in JavaScript.

Declaration

public Object getMember(String name)

getSlot

Method. Retrieves an indexed member of a JavaScript object. Equivalent to "this【索引】" in JavaScript.

Declaration

public Object getSlot(int index)

getWindow

Static method. Returns a JSObject for the window containing the given applet. This method is available only on the client.

Declaration

public static JSObject getWindow(Applet applet)

removeMember

Method. Removes a named member of a JavaScript object.

Declaration

public void removeMember(String name)

setMember

Method. Sets a named member of a JavaScript object. Equivalent to "this.name = value" in JavaScript.

Declaration

public void setMember(String name,
   Object value)

setSlot

Method. Sets an indexed member of a JavaScript object. Equivalent to "this【索引】 = value" in JavaScript.

Declaration

public void setSlot(int index,
   Object value)

toString

Method. Converts a JSObject to a String.

Overrides: toString in class Object

Declaration

public String toString()


【目录】 【上一页】 【下一页】 【索引】

回页面顶部