我想知道是否有办法知道下面的代码中引用了哪个类的原型。
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)