实例变量无法从方法访问

时间:2015-04-13 14:25:04

标签: coffeescript

我是CoffeeScript的新手,但我编写了一个带有构造函数的类,该构造函数为此分配属性。在我的函数中,这些属性没有定义。有人有想法吗?

class ProcessVisualisation
  constructer: (width, devMode = false) ->
    @objProcess = null
    @config =
      devMode: false

  loadProcess: (processPath) ->
    console.log("loadProcess") if (@config.devMode)  # <- config is not defined
    that = @;
    that.processPath = processPath
    $.getJSON @processPath, {}, (response) ->
      that.onProcessLoaded response

pv = new ProcessVisualisation(1023, true)

pv.loadProcess "data/process.json"

1 个答案:

答案 0 :(得分:0)

如评论中所述,修复constructer和功能箭头。

class ProcessVisualisation
  constructor: (width, devMode = false) ->
    @objProcess = null
    @config =
      devMode: false

  loadProcess: (processPath) =>
    console.log("loadProcess") if (@config.devMode)
    @processPath = processPath
    $.getJSON @processPath, {}, (response) =>
      @onProcessLoaded response

pv = new ProcessVisualisation(1023, true)

pv.loadProcess "data/process.json"