请教各位大佬,在环境:
对一个对象的方法:obj.method.name获取的结果总是value。结合调试信息,发现无论用何种方法获这个方法,最终得到的结果都是一个匿名函数的样子 f (){console.log("占位")}。大佬有什么方法来让我通过obj.method获取到的方法不是一个匿名的样子,并正常通过name属性获取方法名称吗,各位大佬帮帮忙,不然要改一堆代码555555(怪我测试没做好)
class A {componentReady() {console.log("占位")}}
async function test(...) {
var pthis = new A(); /* A为实现了construct的代理 */
await ...; // 一个异步函数,省略了名称
console.log("通过reflect查询是否有componentReady");
console.log(Reflect.has(pthis, "componentReady")); /* console> true */
console.log(Reflect.get(pthis, "componentReady")); /* console> f (){console.log("占位")}*/
// 直接查看
console.log(pthis.componentReady); /* console> f (){console.log("占位")}*/
console.log(pthis.componentReady.name); /* console> value */
}
// 出问题的代码
function connect(sender, signal, receiver, slot, connect_type) {
console.log(signal); // <--------这里输出的就是一个匿名的函数,获取名称为value
var _signal_str = typeof signal === "string" ? signal : signal.name;
if (sender.proxys.signalAndSlot_proxy[_signal_str] === undefined) {
sender.proxys.signalAndSlot_proxy[_signal_str] = new Connection(sender, signal);
}
sender.proxys.signalAndSlot_proxy[_signal_str].push_slot(new Slot(receiver, slot, connect_type));
}
// 调用出问题的部分的调用方
class TEST {
static async __meta_new__(...args) {
var pthis = Meta.__meta_new__(...args);
await pthis.__await_async_init__();
pthis.__async_init__();
pthis.__default__();
console.log("输出pthis");
console.log(pthis);
console.log(pthis.componentReady);
console.log("通过reflect查询是否有componentReady");
console.log(Reflect.has(pthis, "componentReady"));
console.log(Reflect.get(pthis, "componentReady"));
console.log(pthis.componentReady);
console.log(pthis.componentReady.name);
console.log("输出内容物");
console.log(pthis.frame.signal_and_slot);
console.log("尝试直接获取");
console.log(pthis.frame.signal_and_slot.componentReady);
console.log("尝试通过proxy获取");
console.log(pthis.proxys.signalAndSlot_proxy.componentReady);
Connection.emit(
pthis.proxys.signalAndSlot_proxy.componentReady
);
console.log(pthis.getComponentReflectInfo())
return pthis;
}
}