【问题标题】:Can I get Ruby's method_missing behavior in typescript?我可以在打字稿中获得 Ruby 的 method_missing 行为吗?
【发布时间】:2017-08-18 16:14:56
【问题描述】:

如果一个类没有实现方法,我想处理引发的错误并使用方法名称注入我自己的代码。

例如:

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 的方法。我们可以在打字稿中得到这个吗?如何得到?

【问题讨论】:

    标签: typescript method-missing


    【解决方案1】:

    不,TypeScript 不能这样做。

    【讨论】:

      猜你喜欢
      • 2014-07-31
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 2013-11-15
      • 2011-06-12
      • 2021-02-07
      • 2019-09-30
      • 2013-09-24
      相关资源
      最近更新 更多