如何获取 JavaScript 代理的目标? [英] How to get the target of a JavaScript Proxy?
本文介绍了如何获取 JavaScript 代理的目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function createProxy() {
const myArray = [Math.random(), Math.random()];
return new Proxy(myArray, {});
}
const myProxy = createProxy();
这里如何访问myProxy
的target
(即myArray
)?
How to access the target
(which is myArray
) of myProxy
here?
我尝试了很多方法.用谷歌搜索了很多博客文章,但没有找到目标:(
I've tried many ways. Was googled many blog posts, but found no way to get the target :(
推荐答案
您可以使用 Object.assign()
:
You can make a copy of the data returned by the proxy using Object.assign()
:
const target_copy = Object.assign({}, my_proxy);
这将适用于所有存在于代理/目标.
This will work for all enumerable own properties existing on the proxy/target.
这篇关于如何获取 JavaScript 代理的目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文