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
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.
claspconst JSClass *The class of the object to create. Added in SpiderMonkey 17
vpjsval *Pointer to a constructor. This must be an object that has a prototype property.
argsJS::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 NULLand 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

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

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

发布评论

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

词条统计

浏览:124 次

字数:4440

最后编辑:7年前

编辑次数:0 次

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