2012-05-06 12 views
1

anom関数から@colsにアクセスしようとしていますが、それは定義されていても(2行目の最後の行に)定義されていません。anomからのインスタンス変数へのアクセス。コーヒースクリプトの関数

 
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') 
+0

何ANOM機能は 'の立つんへの参照を取得することができるように? – epidemian

答えて

3

スリムな矢印の代わりに太い矢印を使用する必要があります。

(d, index)=> 
+0

ありがとうございます。魅力のように働いた。 – Payal

2

使用=>の代わりに - >あなたは、@を使用し、外側のインスタンス

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') 
関連する問題