JSResolveOp 编辑

JSResolveOp is the type of the JSClass.resolve.

Syntax

typedef bool
(* JSResolveOp)(JSContext *cx, JS::HandleObject obj,
                JS::HandleId id, bool *resolvedp); // Added in JSAPI 36
typedef bool
(* JSResolveOp)(JSContext *cx, JS::HandleObject obj,
                JS::HandleId id); // Obsolete since JSAPI 36
NameTypeDescription
cxJSContext *Pointer to the JS context in which the property access is taking place.
objJS::HandleObjectPointer to the object whose properties are being accessed.
idJS::HandleIdThe name or index of the property being resolved.
resolvedpbool *Out parameter. Receives the result of resolve operation.

Description

JSResolveOp callback is a hook which is called when a property is not found on an object.

It resolves a lazy property named by id in obj by defining it directly in obj. Lazy properties are those reflected from some peer native property space (e.g., the DOM attributes for a given node reflected as obj) on demand.

The callback must set *resolvedp to true and return true if the property is resolved, or set *resolvedp to false and return true if the object has no lazy property with the given id; or return false to indicate any other error.

Obsolete since JSAPI 36

The callback must return true if the property is resolved, or if the object has no lazy property with the given id; or false to indicate any other error.

Note: JSNewResolveOp provides a cheaper way to resolve lazy properties.

JSClass hooks

JSClass offers the following hook:

  • JSClass.resolve callback is called when a property is not found on an object. It can be used to implement lazy properties.

     

    JS looks for a property in an object, and if not found, tries to resolve the given id. After calling resolve, the engine looks again to see if resolve defined obj[id]. If so, the property lookup succeeds. If not, the process is repeated with obj's prototype.

See Also

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

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

发布评论

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

词条统计

浏览:112 次

字数:4449

最后编辑:6年前

编辑次数:0 次

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