Node.js 从anom访问实例变量。咖啡脚本中的函数
我正在尝试从anom函数访问@cols,它是未定义的(在最后一行的第二行),即使它已定义 csv = require 'csv' class Inventory constructor: (@file) -> @cols = {} #Read the file and push to cols csv(). fromPath(@file,columns: true ). on 'data', (d,index)-> #push to cols console.log @cols inventory = new Inventory(__dirname + '/sample.csv') csv=需要“csv” 班级清单 构造函数:(@file)-> @cols={} #读取文件并推送到cols csv()。 fromPath(@file,columns:true)。 关于“数据”(d,索引)-> #迫不及待 console.log@cols 库存=新库存(uu dirname+'/sample.csv')Node.js 从anom访问实例变量。咖啡脚本中的函数,node.js,coffeescript,Node.js,Coffeescript,我正在尝试从anom函数访问@cols,它是未定义的(在最后一行的第二行),即使它已定义 csv = require 'csv' class Inventory constructor: (@file) -> @cols = {} #Read the file and push to cols csv(). fromPath(@file,columns: true ). on 'data',
你需要用胖箭头而不是瘦箭头
(d, index)=>
你需要用胖箭头而不是瘦箭头
(d, index)=>
使用=>而不是->这样就可以使用@并获得对外部实例的引用
csv = require 'csv'
class Inventory
constructor: (@file) ->
@cols = {}
#Read the file and push to cols
csv().
fromPath(@file,columns: true).
on 'data', (d,index) =>
#push to cols
console.log @cols
inventory = new Inventory(__dirname + '/sample.csv')
使用=>而不是->这样就可以使用@并获得对外部实例的引用
csv = require 'csv'
class Inventory
constructor: (@file) ->
@cols = {}
#Read the file and push to cols
csv().
fromPath(@file,columns: true).
on 'data', (d,index) =>
#push to cols
console.log @cols
inventory = new Inventory(__dirname + '/sample.csv')
非常感谢。工作很有魅力,谢谢你。工作起来很有魅力。anom function代表什么?anom function代表什么?