mozilla

Revision 117512 of Working with Wrappers

  • Revision slug: JavaScript/Guide/Obsolete_Pages/Working_with_Wrappers
  • Revision title: Working with Wrappers
  • Revision id: 117512
  • Created:
  • Creator: Bkimman
  • Is current revision? No
  • Comment

Revision Content

Working with Wrappers

In JavaScript, a wrapper is an object of the target language data type that encloses an object of the source language. When programming in JavaScript, you can use a wrapper object to access methods and fields of the Java object; calling a method or accessing a property on the wrapper results in a call on the Java object. On the Java side, JavaScript objects are wrapped in an instance of the class netscape.javascript.JSObject and passed to Java.

When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type JSObject; when a JSObject is sent from Java to JavaScript, the runtime engine unwraps it to its original JavaScript object type. The JSObject class provides an interface for invoking JavaScript methods and examining JavaScript properties.


{{template.PreviousNext("Core_JavaScript_1.5_Guide:LiveConnect_Overview", "Core_JavaScript_1.5_Guide:LiveConnect_Overview:JavaScript_to_Java_Communication")}}

Revision Source

<p>
</p>
<h3 name="Working_with_Wrappers"> Working with Wrappers </h3>
<p>In JavaScript, a <i>wrapper</i> is an object of the target language data type that encloses an object of the source language. When programming in JavaScript, you can use a wrapper object to access methods and fields of the Java object; calling a method or accessing a property on the wrapper results in a call on the Java object. On the Java side, JavaScript objects are wrapped in an instance of the class <code>netscape.javascript.JSObject</code> and passed to Java.
</p><p>When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type <code>JSObject</code>; when a <code>JSObject</code> is sent from Java to JavaScript, the runtime engine unwraps it to its original JavaScript object type. The <code>JSObject</code> class provides an interface for invoking JavaScript methods and examining JavaScript properties.
</p><p><br>
{{template.PreviousNext("Core_JavaScript_1.5_Guide:LiveConnect_Overview", "Core_JavaScript_1.5_Guide:LiveConnect_Overview:JavaScript_to_Java_Communication")}}
</p>
Revert to this revision