Simplified mode to define a property from a destructuring

Asked

Viewed 22 times

0

Considering the example below: Is there a way for me to simplify?

It is possible to define _get and _set directly as a property without going through const [_get, _set] before?

const App = class {
  constructor() {
    const [_get, _set] = FnTal()
    this._get = _get;
    this._set = _set;
  }
}

1 answer

1

Soon after, I put just out of curiosity the this within the array, and that cool, it worked!

For a moment I imagined that this could be a Babel facility, so I tested it on the browser console and Nodejs, on both worked.

Now I know it is also possible to define properties using destructuring.

const FnTal = () => [() => {}, () => []]

const App = class {
  constructor() {
    [this._get, this._set] = FnTal()
  }
}

const app = new App() // App {_get: ƒ, _set: ƒ}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.