0

I have a collection of helper-functions, like this:

var myHelpers = {

    addFoo: ( name ) => {
        return name + 'foo';
    },

    addFooBar: ( name ) => {
        return this.addFoo( name ) + 'bar'; // This is what throws the error.
    }

}

window.myHelpers = myHelpers;
export default myHelpers;

And I then use it like this:

import myHelpers from "./myHelpers";

let test = 'abc';
test = myHelpers.addFooBar( test );

But this throws the error: Uncaught TypeError: Cannot read properties of undefined

... How do I make these functions call eachother, without getting this error?

Zeth
  • 1,662
  • 3
  • 35
  • 72

1 Answers1

1

Use myHelpers instead of this

addFooBar: name => {
  return myHelpers.addFoo(name) + 'bar'
},
aerial
  • 1,158
  • 3
  • 5
  • 14