调用类中父对象外部的函数

Call function outside parent object in a class

本文关键字:外部 函数 对象 调用      更新时间:2023-09-26
class Test
    f1: -> console.log 'f1'
    f2: -> console.log 'f2'
    f:
        f3: -> f1()
test = new Test
test.f.f3()

当我在NodeJS中运行这个时,我得到的是:

ReferenceError: f1 is not defined

我想从f.f3运行f1。我该怎么做?

谢谢!

我的第一个答案不正确,但这是有效的(稍作修改(:

class Test
  f1: -> console.log 'f1'
  f2: -> console.log 'f2'
  f: =>
    f3: => @f1()
test = new Test
test.f().f3()