を使用して:シンボルターゲットオブジェクトからプロパティを取得し、次のコードを使用してES6プロキシオブジェクト
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: Cannot convert a Symbol value to a string
、これは上の発生ライン:
new Error(`The assertion library used does not have '${prop}' property or method.`));
私は前にプロキシを使用している、と私はのProxのgetメソッドに渡されるシンボルを見たことがありませんy。誰もがこの問題を回避する方法を知っていますか?
なぜシンボルがプロキシget関数に渡され、それを適切に処理するのですか?
get関数に送信されるプロップは 'Symbol(util.inspect.custom)'です。他にも送信されるものがあると思います。 –
私は、コードをデバッグする必要があると思います。シンボルが 'if(typeof prop === 'symbol'){'によってフィルタリングされなくてはならないようです。 – Qwertiy