我有一个Child扩展类Test。我想从Testfrom调用一个函数Child。
我试过这个:
class Test
constructor: ->
@i = 'hello world'
f1: -> console.log @i
f2: -> console.log 'hello'
class Child extends Test
run: ->
Test::f1()
hello = new Child()
hello.run()
当我打电话时hello.run(),它会打电话Test.f1(),但结果是undefined。@i它没有在运行之前设置静态变量Test.f1()。
如果我切换Test::f1()到Test::f2(),它会给我正确的结果。
我需要知道当我创建一个时我应该如何运行,以便在Test我运行时定义。constructornew Child()@iTestTest::f1()Child.run()
谢谢!:D