如何测试对象是否是Proxy? [英] How to test if an object is a Proxy?

查看:143
本文介绍了如何测试对象是否是Proxy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试JavaScript对象是否为代理服务器 。简单的方法

I would like to test if a JavaScript object is a Proxy. The trivial approach

if (obj instanceof Proxy) ...

在这里不起作用,也不会遍历 Proxy.prototype 的原型链,因为所有相关操作都是

doesn't work here, nor does traversing the prototype chain for Proxy.prototype, since all relevant operations are effectively backed by the underlying target.

是否可以测试任意对象是否为代理?

Is it possible to test if an arbitrary object is a Proxy?

推荐答案

http://www.2ality.com/2014/12 /es6-proxies.html


无法确定对象是否为代理(透明虚拟化) 。

It is impossible to determine whether an object is a proxy or not (transparent virtualization).

这篇关于如何测试对象是否是Proxy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆