JS_New 编辑
This article covers features introduced in SpiderMonkey 1.8
Create an object as though by using the new
keyword and a JavaScript function.
Syntax
JSObject *
JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); // Added in JSAPI 32
JSObject *
JS_New(JSContext *cx, JSObject *ctor, unsigned argc, jsval *argv); // Obsolete since JSAPI 32
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 . |
ctor | JS::HandleObject | The constructor function object. |
args | JS::HandleValueArray & | An array of argument values to pass to the constructor. Added in SpiderMonkey 38 |
argc | unsigned | The number of arguments to pass to the constructor. Obsolete since JSAPI 32 |
argv | jsval * | Pointer to the element 0 of an array of argument values to pass to the constructor. If argc is 0 , this may be NULL . Obsolete since JSAPI 32 |
Description
JS_New
creates a new object as though by using the new operator, as described in ECMA 262-3 §11.2.2.
JS_New(cx, ctor, args)
is equivalent to the JavaScript expression new ctor(...args)
, and JS_New(cx, ctor, argc, argv)
is equivalent to the JavaScript expression new ctor(argv[0], argv[1], ... argv[argc-1])
. If ctor
is not an object that can be used as a constructor, a TypeError
is raised.
On success, JS_New returns a pointer to the new object. On error, it returns NULL
.
See Also
- MXR ID Search for
JS_New
- bug 480850 - added
- bug 959787 - added
args
parameter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论