【发布时间】:2023-12-29 13:37:01
【问题描述】:
如果一个类没有实现方法,我想处理引发的错误并使用方法名称注入我自己的代码。
例如:
class Foo {
def method_missing(methodName) {
console.log(`${methodName} was called`);
}
}
let foo = new Foo();
foo.bar(); // should print 'bar was called' in the console
在 ruby 中,每个提供此行为的类都有一个名为 method_missing 的方法。我们可以在打字稿中得到这个吗?如何得到?
【问题讨论】: