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_DefineObject

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

あるオブジェクトのプロパティとなるオブジェクトを生成する関数です。 Create an object that is a property of another object.

構文

JSObject * JS_DefineObject(JSContext *cx, JSObject *obj,
    const char *name, JSClass *clasp, JSObject *proto,
    uintN flags);
Name Type Description
cx JSContext * エラー報告に用いるランタイム環境から派生したコンテキストへのポインタPointer to a JS context from which to derive runtime information for error reporting. リクエストが必要。 (JS_THREADSAFE ビルドでは、呼び出し側はこの JSContext 上のリクエストでなければなりません。)
obj JSObject * 生成したオブジェクトをプロパティとして持つオブジェクトへのポインタObject to which this new object belongs as a property.
name const char * objでのプロパティ名Name of the property that encapsulates the new object in <code>obj</code>.
clasp JSClass * オブジェクト生成に用いるクラスClass to use for the new object.
proto JSObject * オブジェクト生成に用いるプロトタイプPrototype object to use for the new object.
flags uintN 生成したオブジェクトの属性を指定するフラグProperty flags for the new object.

説明

JS_DefineObjectは、オブジェクトのインスタンスを生成し、それを引数objで指定した既存オブジェクトのプロパティとして設定する関数です。引数nameで、objでのプロパティ名を指定し、flagsでそのプロパティの属性を指定します。以下の表で設定可能なflagsの値を示します。これらの値は単一、あるいは複数の値の論理和として引数に与えることができます。 <code>JS_DefineObject</code> instantiates and names a new object for an existing object, <code>obj</code>. <code>name</code> is the property name to assign to <code>obj</code> to hold the new object, and <code>flags</code> contains the property flags to set for the newly created property. The following table lists possible values you can pass in <code>flags</code>, either singly, or <code>OR</code>'d together:

Flag Purpose
JSPROP_ENUMERATE forinループを使ったアクセス(Core JavaScript 1.5 Guide:Object Manipulation Statements)を可能にします。Property is visible to <code>for</code> and <code>in</code> loops.
JSPROP_READONLY プロパティの値を読み取り専用にします。Property is read only.
JSPROP_PERMANENT プロパティの削除を不可能にします。Property cannot be deleted.
JSPROP_EXPORTED Property can be imported by other objects.
JSPROP_INDEX Property is actually an index into an array of properties, and is cast to a const char *.

引数claspはオブジェクトの生成時に用いる基底クラスへのポインタ、引数protoはプロトタイプへのポインタをそれぞれとります。protoNULLを指定した場合、JavaScriptは自分自身をプロトタイプとします。引数objはオブジェクトの親オブジェクトになります。 <code>clasp</code> is a pointer to the base class to use when creating the new object, and <code>proto</code> is an pointer to the prototype upon which to base the new object. If you set <code>proto</code> to <code>NULL</code>, JS sets the prototype object for you. The parent object for the new object is set to <code>obj</code>.

JS_DefineObjectが成功したとき、返値は新たに生成したプロパティオブジェクトへのポインタになります。もしすでにプロパティが設定されていた場合、オブジェクトは生成されず、返り値はNULLになります。 <code>JS_DefineObject</code> returns a pointer to the newly created property object if successful. If the property already exists, or cannot be created, <code>JS_DefineObject</code> returns <code>NULL</code>.

参照

Groups Functions
Documents LXR ID Search
Entries

JSClass, JS_DefineConstDoubles, JS_DefineElement, JS_DefineFunction, JS_DefineFunctions, JS_DefineProperties, JS_DefineProperty, JS_DefinePropertyWithTinyId, JS_NewObject, JS_ValueToObject

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

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