JS_NewObjectForConstructor 编辑
Convenience function to create a new object exactly as a constructor function would.
Syntax
JSObject *
JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); // Added in JSAPI 32
JSObject *
JS_NewObjectForConstructor(JSContext *cx, JSClass *clasp, const jsval *vp); // Added in JSAPI 14, Obsolete since JSAPI 32
JSObject *
JS_NewObjectForConstructor(JSContext *cx, const jsval *vp); // Obsolete since JSAPI 14
Name | Type | Description |
---|---|---|
cx | JSContext * | The context in which to create the new object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
clasp | const JSClass * | The class of the object to create. Added in SpiderMonkey 17 |
vp | jsval * | Pointer to a constructor. This must be an object that has a prototype property. |
args | JS::CallArgs & | Call argument to get a constructor as callee . Added in SpiderMonkey 38 |
Description
JS_NewObjectForConstructor
creates a new object exactly as the given constructor would if invoked with new
. This function does not run the code of the constructor function--it just creates the object.
If the constructor argument is not an object jsval
, this function will assert (in debug builds). If the constructor does not have a prototype
property, this function will return NULL
and set an exception on cx
.
The standard object creation API, JS_NewObject
, takes explicit arguments for the class, prototype, and parent of the new object. With JS_NewObjectForConstructor
, the prototype and parent are determined by the constructor, and class is still determined by the caller. The prototype is the prototype of the constructor if it is an object, otherwise NULL
. The parent is the constructor's parent.
See Also
- MXR ID Search for
JS_NewObjectForConstructor
JS_NewObject
OBJECT_TO_JSVAL
- bug 581263 - added
- bug 738075 - added
clasp
parameter - bug 959787 - added
args
parameter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论