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
NameTypeDescription
cxJSContext *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.
ctorJS::HandleObjectThe constructor function object.
argsJS::HandleValueArray &An array of argument values to pass to the constructor. Added in SpiderMonkey 38
argcunsignedThe number of arguments to pass to the constructor. Obsolete since JSAPI 32
argvjsval *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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:73 次

字数:3361

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文