Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

JS ConstructObject

このテンプレートは廃止されています。使用しないで下さい。

新たにJavaScriptオブジェクトを生成し、コンストラクタを呼び出します。 Create a new JavaScript object and invoke its constructor.

構文

JSObject * JS_ConstructObject(JSContext *cx, JSClass *clasp,
    JSObject *proto, JSObject *parent);
Name Type Description
cx JSContext * 新たなオブジェクトを配置するコンテキストThe context in which to create the new object. リクエストが必要。 (JS_THREADSAFE ビルドでは、呼び出し側はこの JSContext 上のリクエストでなければなりません。)</td> </tr> <tr> <td><code>clasp</code></td> <td><code>JSClass *</code></td> <td>オブジェクト生成時に利用するクラスへのポインタ。<code>NULL</code>を指定したときは、一般的なJavaScript <code>Object</code>が生成されます。<!--Pointer to the class to use for the new object. If this is <code>NULL</code>, an ordinary JavaScript <code>Object</code> is created.
proto JSObject * クラスとなるプロトタイプオブジェクトへのポインタPointer to the prototype object to use for the new class.
parent JSObject * 新たなオブジェクトの __parent__ プロパティに指定するオブジェクトへのポインタPointer to which to set the new object's __parent__ property.

解説

JS_ConstructObjectは、与えられたクラス、プロトタイプ、親オブジェクト、コンストラクタ関数をもとに新たなオブジェクトのインスタンスを生成する関数です。cxには、新たなオブジェクトを配置するランタイムと結び付けられたコンテキストへのポインタを指定します。claspには、ファイナライズ処理などの内部関数が定義された既存クラスへのポインタを指定します。protoは、新たなオブジェクトのプロトタイプとなるオブジェクトへのポインタを指定する引数です。 <code>JS_ConstructObject</code> instantiates a new object based on a specified class, prototype, and parent object, and then invokes its constructor function. <code>cx</code> is a pointer to a context associated with the runtime in which to establish the new object. <code>clasp</code> is a pointer to an existing class to use for internal methods, such as finalize. <code>proto</code> is an optional pointer to the prototype object with which to associate the new object.

自分自身をプロトタイプオブジェクトにするには、protoNULLを指定してください。このとき、claspがプロトタイプを定義している場合には、JS_ConstructObjectは新たなオブジェクトのプロトタイプにそれを用います。定義していない場合は、空オブジェクトスタブをプロトタイプとします。 Set <code>proto</code> to <code>NULL</code> to force JS to assign a prototype object for you. In this case, <code>JS_ConstructObject</code> attempts to assign the new object the prototype object belonging to <code>clasp</code>, if one is defined there. Otherwise, it creates an empty object stub for the prototype.

parentには、新規オブジェクトの親プロパティとなるオブジェクトへのポインタを指定します。この引数はオプションであり、parentNULLを指定することで親プロパティを持たないオブジェクトになります。 <code>parent</code> is an optional pointer to an existing object to which to set the new object's parent object property. You can set <code>parent</code> to <code>NULL</code> if you do not want to set the parent property.

JS_ConstructObjectが成功したとき、新たに生成されたオブジェクトへのポインタをその返値とします。失敗したときはNULLを返します。 On success, <code>JS_ConstructObject</code> returns a pointer to the newly instantiated object. Otherwise it returns <code>NULL</code>.

関連項目

MXR ID で JS_ConstructObject

JS_DefineObject, JS_GetFunctionObject, JS_NewArrayObject, JS_NewObject, JS_ValueToObject

ドキュメントのタグと貢献者

 このページの貢献者: fscholz, Norihiro
 最終更新者: fscholz,