S
S
Sergey Sokolov2018-07-04 21:58:19
JavaScript
Sergey Sokolov, 2018-07-04 21:58:19

How to access your own property in a module method if someone else's context is attached?

There is a module like:

/*  AB.js  */
export default {
  a: 'AAA',
  b: function() {
    this.a = '3 A';
  }
}

But the method b()is called with another context attached:
import AB from './AB'

setTimeout( AB.b.bind(null), 0);

b()How can I make my own property available in a method a?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RidgeA, 2018-07-04
@sergiks

const self = {
  a: 'AAA',
  b: function() {
    self.a = '3 A';
  }
}

export default self;

A
Alexey Ukolov, 2018-07-05
@alexey-m-ukolov

Лучше вообще просто стрелочную функцию использовать в AB.js.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question