0

I've imported a function from a module. In that function I need to get a property of the class without sending the class as a parameter to the function, because I cannot send the parameter every time I call the function.

What I've tried, but didn't worked

import {x} from './export.js';

class foo {
  constructor() {
    x();
  }
  str = 'A String';
}

export.js

export function() {
  console.log(this.str); // Or Maybe Something Else...
}

1 Answers1

0

this inside function in not-strict mode is refer to the global object hence you cannot use this to access class properties.

you can get more information on this in this answer

Rohit Saw
  • 26
  • 5