Saturday, 6 May 2017

Fat arrow subroutine can't access 'this'

I'm under the impression that using fat arrows => for subroutines, I would be able to access the bucket variable but getting error as below. What am I doing wrong here?

const csv = require('csvtojson');

exports.uploadedCsv = functions.storage.object().onChange(event => {
    const bucket = gcs.bucket(csvData.bucket);
    var readStream = bucket.file(csvData.name).createReadStream();
    csv().fromStream(readStream)
        .on('json', (jsonObj) => {
           // do some stuff
        })
        .on('done', () => {
            this.bucket.child(csvData.name).delete()
            // TypeError: Cannot read property 'child' of undefined
            // at Converter.csv.fromStream.on.on
        })
    })



via AshClarke

No comments:

Post a Comment