使用以下代码:
const assrt = function () {
try {
return chaiAssert.apply(null, arguments);
}
catch (e) {
return handleError(e);
}
};
v.assert = new Proxy(assrt, {
get: function (target, prop) {
if(typeof prop === 'symbol'){
// I don't know what to do with symbols, so return
return Reflect.get(...arguments);
}
// but here! we still get properties that don't exist
if(!chaiAssert[prop]){
return handleError(
new Error(`The assertion library used does not have '${prop}' property or method.`)
);
}
return function () {
try {
return chaiAssert[prop].apply(null, arguments);
}
catch (e) {
return handleError(e);
}
}
}
});
我使用此代码得到的错误是:
TypeError:无法将符号值转换为字符串
这发生在线上:
new Error(`The assertion library used does not have '${prop}' property or method.`));
我以前使用过代理,我从未见过将符号传递给代理的 get 方法。有谁知道如何规避这个问题?
为什么将符号传递给代理获取函数,我该如何正确处理?