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_NewObject

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

概要

オブジェクトのインスタンスを生成する関数です。Instantiates a new object.

構文

JSObject * JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto,
    JSObject *parent);
Name Type Description
cx JSContext * ランタイム環境へのアクセスに用いる JSContext ポインタPointer to a JS context from which to derive runtime information.
clasp JSClass * オブジェクト生成に用いるクラスへのポインタPointer to the class to use for the new object.
proto JSObject * クラスとして用いる prototype オブジェクトへのポインタPointer to the prototype object to use for the new class.
parent JSObject * 新規オブジェクトの__parent__プロパティになる親オブジェクトへのポインタ。Pointer to which to set the new object's <code>__parent__</code> property.

説明

JS_NewObjectは、引数に指定したクラス、プロトタイプ、親オブジェクトを元にしてオブジェクトのインスタンスを生成する関数です。cxは、新規オブジェクトを生成するランタイム環境の子となるコンテキストへのポインタです。claspは、finalizeのような内部で定義されたメソッドを使う既存クラスへのポインタです。protoは、新規に生成するオブジェクトのプロトタイプとなるオブジェクトへのポインタです。 <code>JS_NewObject</code> instantiates a new object based on a specified class, prototype, and parent object. <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 <code>finalize</code>. <code>proto</code> is an optional pointer to the prototype object with which to associate the new object.

Set proto to NULL to force JS to assign a prototype object for you. In this case, JS_NewObject attempts to assign the new object the prototype object belonging to clasp, if one is defined there. Otherwise, it creates an empty object stub for the prototype.

引数parentは、新たに生成したオブジェクトをプロパティとして持つ親オブジェクトを指定するものです。__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 parent to <code>NULL</code> if you do not want to set the <code>__parent__</code> property.

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

注記

既存オブジェクトのプロパティとなるオブジェクトを生成するには、JS_DefineObjectを用いてください。 To create a new object that is a property of an existing object, use <code>JS_DefineObject</code>.

参照

Groups Functions
Documents LXR ID Search
Entries

JSClass, JS_ConstructObject, JS_DefineObject, JS_GetFunctionObject, JS_NewArrayObject, JS_ValueToObject

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

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