CoffeeScript如何知道this.variable所指的类

时间:2015-03-24 04:58:57

标签: javascript coffeescript

我想知道是否有办法知道下面的代码中引用了哪个类的原型。

class Foo
  test : ->
    console.log "This is from Foo"
  test2 : ->
    console.log "This is from Foo"

class Bar extends Foo
  test2 : ->
    super

class Baz extends Bar
  constructor : ->
    @test() # this refer to Foo's test directly
    @test2() # this refer to Bar's test2 but end up calling Foo's test2

Baz的@test()@test2()都引用了Bar的test和test2。由于test2中没有Bar原型,@ test2引用到Foo test2

我的问题是,当我在Multiplex嵌套类中调用@something时,有没有办法知道哪个原型被引用。

我想要的结果是

@test -> Foo
@test2 -> Bar (It's perfect If it's able to detect it's ended up calling Foo's test2)

0 个答案:

没有答案