JavaScript Javascript: Mixing in a getter (object spread)

I tried creating mixing in a getter into a JS object via the spread operator syntax, however it always seems to return null.

HTML:

<body>
  <div id="wrapperA"></div>
  <div id="wrapperB"></div>
</body>
<script src='./test.js'></script>

JS:

"use strict";

const mixin = {
    get wrapper() { return document.getElementById(this.wrappername); }
}

const wrapperA = {
  wrappername: 'wrapperA',
  ...mixin
}

const wrapperB = {
  wrappername: 'wrapperB',
  ...mixin
}

console.log(wrapperA);
console.log(wrapperB);

Console output:

{wrappername: "wrapperA", wrapper: null}
{wrappername: "wrapperB", wrapper: null}

This links to an extension function that is supposed to work, and from what I can tell the code above created an unintentional closure. However, it reads quite poorly compared to the ... syntax. Does anybody know how to get the code to work with the latter solution? Do the ES devs know about this issue and will it be fixed in ES7?

Answer:1

I have an two elements fruits and crates fruits is an array containing a list of different fruits like: ["apple","orange","mango","pear"] crates is an array of objects which contains fruits in it ...

I have an two elements fruits and crates fruits is an array containing a list of different fruits like: ["apple","orange","mango","pear"] crates is an array of objects which contains fruits in it ...

How can I translate this curl script to an AJAX request in JavaScript? curl -X POST -d "grant_type=password&username=admin&password=Demo1234" -u "<ClientID>:<ClientSecret&...

How can I translate this curl script to an AJAX request in JavaScript? curl -X POST -d "grant_type=password&username=admin&password=Demo1234" -u "<ClientID>:<ClientSecret&...

  1. translate curl to javascript

I'm a bit confused after reading about how to use bitmasks to store boolean values. I would like to have a set of boolean values and then generate a unique integer for each combination of the values. ...

I'm a bit confused after reading about how to use bitmasks to store boolean values. I would like to have a set of boolean values and then generate a unique integer for each combination of the values. ...

I am not able to show two bar charts in one page. I have tried both ways, implementing these in two different <script> sections in and in one <script> section also. If one is shown if I ...

I am not able to show two bar charts in one page. I have tried both ways, implementing these in two different <script> sections in and in one <script> section also. If one is shown if I ...

  1. google charts work offline
  2. google charts not working
  3. google charts not working in ie11
  4. google charts not working in safari
  5. google charts stopped working
  6. google charts not working in chrome
  7. google charts not working in firefox
  8. google charts not working in internet explorer
  9. google charts not working in ie
  10. google charts not working in edge
  11. does google charts work offline
  12. google.charts.setonloadcallback not working
  13. google charts animation not working
  14. google.charts.load not working
  15. google charts colors not working
  16. google charts chartarea not working
  17. google charts options not working
  18. google charts ticks not working
  19. google charts isstacked not working
  20. google charts interpolatenulls not working