Nested javascript arrays: access across module boundariesHow do I check if an array includes an object in JavaScript?Deleting array elements in JavaScript - delete vs spliceHow to insert an item into an array at a specific index (JavaScript)?How do you check if a variable is an array in JavaScript?Sorting an array of JavaScript objects by propertyHow do I empty an array in JavaScript?Loop through an array in JavaScriptHow do I remove a particular element from an array in JavaScript?How can I add new array elements at the beginning of an array in Javascript?For-each over an array in JavaScript?
Method to test if a number is a perfect power?
How can a function with a hole (removable discontinuity) equal a function with no hole?
Applicability of Single Responsibility Principle
What happens if you roll doubles 3 times then land on "Go to jail?"
Is the destination of a commercial flight important for the pilot?
How to safely derail a train during transit?
System.debug(JSON.Serialize(o)) Not longer shows full string
Balance Issues for a Custom Sorcerer Variant
Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?
Closest Prime Number
Why escape if the_content isnt?
How to draw lines on a tikz-cd diagram
Is this apparent Class Action settlement a spam message?
What does the word "Atten" mean?
Term for the "extreme-extension" version of a straw man fallacy?
How to check is there any negative term in a large list?
when is out of tune ok?
Lay out the Carpet
How did Arya survive the stabbing?
Purchasing a ticket for someone else in another country?
What is the difference between "behavior" and "behaviour"?
Tiptoe or tiphoof? Adjusting words to better fit fantasy races
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
How does it work when somebody invests in my business?
Nested javascript arrays: access across module boundaries
How do I check if an array includes an object in JavaScript?Deleting array elements in JavaScript - delete vs spliceHow to insert an item into an array at a specific index (JavaScript)?How do you check if a variable is an array in JavaScript?Sorting an array of JavaScript objects by propertyHow do I empty an array in JavaScript?Loop through an array in JavaScriptHow do I remove a particular element from an array in JavaScript?How can I add new array elements at the beginning of an array in Javascript?For-each over an array in JavaScript?
I'd be grateful if someone could provide a working example of a nested array populated and accessible across ES6 module boundaries, that is to say with setter and (especially) getter methods called from a dependent module.
No matter which design pattern I base my attempts on, setter methods work fine but getter methods invoked across module boundaries invariably provoke the following:
TypeError: nested_array[at_whatever_depth] is undefined
I am not convinced of polluting potentially simple principles with complex examples, but here is roughly what I'm trying to do.. I'd be mega content with something simpler that actually works..
Previously, the array was populated in the same scope as the code which used it. What follows was an attempt at 'modularising' it. The code simply readies an imported music font ('glyphs') for display.
This particular example goes back to more or less where I started: a state module approach. (Others tried? The slightly more advanced basket and revealing module, and a lot of variations thereon..).
var music_glyphs_store = (function ()
var pub = ;
pub.state = [],
pub.setGlyphByName = function (glyph_name, horiz_adv_x, path)
pub.state.push(glyph_name);
pub.state[glyph_name] = [];
pub.state[glyph_name]["glyph_name"] = glyph_name;
pub.state[glyph_name]["horiz-adv-x"] = horiz_adv_x;
pub.state[glyph_name]["d"] = path;
,
pub.getGlyphByName = function(glyph_name)
return pub.state[glyph_name];
return pub; // expose externally
)();
export music_glyphs_store ;
The problematic call is to music_glyphs_store.getGlyphByName() and its variants. I know that the glyphs I'm trying to retrieve are stored in the array: the dependent module simply can't access them..
Here's what a typical font element might look like in the original, raw, svg file.
<glyph glyph-name="scripts.sforzato" unicode="" horiz-adv-x="219"
d="M-206.864 126.238c-8.498 -2.679 -12.964 -10.131 -12.964 -17.821c0 -6.455 3.146 -13.0777 9.696 -17.1846c1.8 -1.1369 -9.04799 1.8 139.074 -37.9895l103.026 -27.7105l71.6682 -19.279c12.269 -3.31579 22.358 -6.11053 22.358 -6.25263
c0 -0.142105 -10.089 -2.93684 -22.358 -6.25264l-71.6682 -19.2789l-103.026 -27.7105c-154.231 -41.4474 -137.132 -36.7106 -140.4 -38.8895c-5.625 -3.7263 -8.44299 -9.80721 -8.44299 -15.8892c0 -6.056 2.795 -12.113 8.396 -15.848
c3.147 -2.07201 6.077 -3.08401 9.87399 -3.08401c3.061 0 6.685 0.658005 11.442 1.94801l161.053 43.2942c228.488 61.4133 240.486 64.527 240.486 65.2851c0 0.0888996 -0.164993 0.1455 -0.164993 0.26c0 0.0702 0.0619965 0.1623 0.263 0.297099
c5.63699 3.7421 8.45499 9.80522 8.45499 15.8684c0 6.06316 -2.81799 12.1263 -8.45499 15.8684c-3.17401 2.0842 2.27299 0.521 -46.137 13.5474l-194.447 52.2947l-161.053 43.2947c-4.795 1.316 -8.506 1.94601 -11.581 1.94601
c-1.907 0 -3.57001 -0.243004 -5.093 -0.714005z" />
Here's how the calls are set up:
import music_glyphs_store from "./music_glyphs_store.js";
import * as d3 from "d3";
Then (having, at some point, loaded and parsed the raw xml strings from file):
d3.selectAll(note_glyphs.getElementsByTagName("glyph")).each(function(d, i)
var glyph_name = this.getAttribute("glyph-name");
var horiz_adv_x = this.getAttribute("horiz-adv-x");
var path = this.getAttribute("d");
music_glyphs_store.setGlyphByName(glyph_name, horiz_adv_x, path);
);
Whatever the purpose, the idea is that stored values can later be recovered using calls to the above methods. For example:
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("brace446"));
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("accidentals.natural.arrowdown"));
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("noteheads.s2slash"));
In deference to the ES6 module conventions, I later tried eliminating the duplicate ('superflous') state module wrapper (goal: better selective exposure of inner variables and functions) - but to no avail. Declaring the array root variable at window (global) scope also brings no improvement.
The motivation for all this is a migration of existing code -with conventional html inclusions- to Webpack with it's module export/import approach, thereby also leveraging node.js's strengths. While breaking a lot of previously working code, I'm optimistic about the long-term benefits..
The problem would seem to lie with the visibility/scope of dynamically allocated memory. I begin to wonder if nested arrays can be used in a diverse Webpack context at all. Am I perhaps barking up a dead tree?
javascript arrays webpack node-modules
add a comment |
I'd be grateful if someone could provide a working example of a nested array populated and accessible across ES6 module boundaries, that is to say with setter and (especially) getter methods called from a dependent module.
No matter which design pattern I base my attempts on, setter methods work fine but getter methods invoked across module boundaries invariably provoke the following:
TypeError: nested_array[at_whatever_depth] is undefined
I am not convinced of polluting potentially simple principles with complex examples, but here is roughly what I'm trying to do.. I'd be mega content with something simpler that actually works..
Previously, the array was populated in the same scope as the code which used it. What follows was an attempt at 'modularising' it. The code simply readies an imported music font ('glyphs') for display.
This particular example goes back to more or less where I started: a state module approach. (Others tried? The slightly more advanced basket and revealing module, and a lot of variations thereon..).
var music_glyphs_store = (function ()
var pub = ;
pub.state = [],
pub.setGlyphByName = function (glyph_name, horiz_adv_x, path)
pub.state.push(glyph_name);
pub.state[glyph_name] = [];
pub.state[glyph_name]["glyph_name"] = glyph_name;
pub.state[glyph_name]["horiz-adv-x"] = horiz_adv_x;
pub.state[glyph_name]["d"] = path;
,
pub.getGlyphByName = function(glyph_name)
return pub.state[glyph_name];
return pub; // expose externally
)();
export music_glyphs_store ;
The problematic call is to music_glyphs_store.getGlyphByName() and its variants. I know that the glyphs I'm trying to retrieve are stored in the array: the dependent module simply can't access them..
Here's what a typical font element might look like in the original, raw, svg file.
<glyph glyph-name="scripts.sforzato" unicode="" horiz-adv-x="219"
d="M-206.864 126.238c-8.498 -2.679 -12.964 -10.131 -12.964 -17.821c0 -6.455 3.146 -13.0777 9.696 -17.1846c1.8 -1.1369 -9.04799 1.8 139.074 -37.9895l103.026 -27.7105l71.6682 -19.279c12.269 -3.31579 22.358 -6.11053 22.358 -6.25263
c0 -0.142105 -10.089 -2.93684 -22.358 -6.25264l-71.6682 -19.2789l-103.026 -27.7105c-154.231 -41.4474 -137.132 -36.7106 -140.4 -38.8895c-5.625 -3.7263 -8.44299 -9.80721 -8.44299 -15.8892c0 -6.056 2.795 -12.113 8.396 -15.848
c3.147 -2.07201 6.077 -3.08401 9.87399 -3.08401c3.061 0 6.685 0.658005 11.442 1.94801l161.053 43.2942c228.488 61.4133 240.486 64.527 240.486 65.2851c0 0.0888996 -0.164993 0.1455 -0.164993 0.26c0 0.0702 0.0619965 0.1623 0.263 0.297099
c5.63699 3.7421 8.45499 9.80522 8.45499 15.8684c0 6.06316 -2.81799 12.1263 -8.45499 15.8684c-3.17401 2.0842 2.27299 0.521 -46.137 13.5474l-194.447 52.2947l-161.053 43.2947c-4.795 1.316 -8.506 1.94601 -11.581 1.94601
c-1.907 0 -3.57001 -0.243004 -5.093 -0.714005z" />
Here's how the calls are set up:
import music_glyphs_store from "./music_glyphs_store.js";
import * as d3 from "d3";
Then (having, at some point, loaded and parsed the raw xml strings from file):
d3.selectAll(note_glyphs.getElementsByTagName("glyph")).each(function(d, i)
var glyph_name = this.getAttribute("glyph-name");
var horiz_adv_x = this.getAttribute("horiz-adv-x");
var path = this.getAttribute("d");
music_glyphs_store.setGlyphByName(glyph_name, horiz_adv_x, path);
);
Whatever the purpose, the idea is that stored values can later be recovered using calls to the above methods. For example:
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("brace446"));
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("accidentals.natural.arrowdown"));
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("noteheads.s2slash"));
In deference to the ES6 module conventions, I later tried eliminating the duplicate ('superflous') state module wrapper (goal: better selective exposure of inner variables and functions) - but to no avail. Declaring the array root variable at window (global) scope also brings no improvement.
The motivation for all this is a migration of existing code -with conventional html inclusions- to Webpack with it's module export/import approach, thereby also leveraging node.js's strengths. While breaking a lot of previously working code, I'm optimistic about the long-term benefits..
The problem would seem to lie with the visibility/scope of dynamically allocated memory. I begin to wonder if nested arrays can be used in a diverse Webpack context at all. Am I perhaps barking up a dead tree?
javascript arrays webpack node-modules
1
Arrays usually do not have "setter" or "getter" methods. Without seeing the code involved, I doubt anybody will figure out the problem.
– Pointy
Mar 21 at 15:55
setter + getter wrapper functions. If I post code, it would just be one of many unsuccessful attempts. I'd prefer, where possible, to see a proven example.
– user1019696
Mar 21 at 15:58
1
It's not even clear what you mean by "nested array"; if you export a reference to an object of any kind, an importing module has access to the entire object graph.
– Pointy
Mar 21 at 16:17
Don't abuse arrays when you need objects
– Bergi
Mar 23 at 14:33
Please post the code that imports your module and uses themusic_glyphs_store
object so that we have a Minimal, Complete, and Verifiable example of what doesn't work.
– Bergi
Mar 23 at 14:35
add a comment |
I'd be grateful if someone could provide a working example of a nested array populated and accessible across ES6 module boundaries, that is to say with setter and (especially) getter methods called from a dependent module.
No matter which design pattern I base my attempts on, setter methods work fine but getter methods invoked across module boundaries invariably provoke the following:
TypeError: nested_array[at_whatever_depth] is undefined
I am not convinced of polluting potentially simple principles with complex examples, but here is roughly what I'm trying to do.. I'd be mega content with something simpler that actually works..
Previously, the array was populated in the same scope as the code which used it. What follows was an attempt at 'modularising' it. The code simply readies an imported music font ('glyphs') for display.
This particular example goes back to more or less where I started: a state module approach. (Others tried? The slightly more advanced basket and revealing module, and a lot of variations thereon..).
var music_glyphs_store = (function ()
var pub = ;
pub.state = [],
pub.setGlyphByName = function (glyph_name, horiz_adv_x, path)
pub.state.push(glyph_name);
pub.state[glyph_name] = [];
pub.state[glyph_name]["glyph_name"] = glyph_name;
pub.state[glyph_name]["horiz-adv-x"] = horiz_adv_x;
pub.state[glyph_name]["d"] = path;
,
pub.getGlyphByName = function(glyph_name)
return pub.state[glyph_name];
return pub; // expose externally
)();
export music_glyphs_store ;
The problematic call is to music_glyphs_store.getGlyphByName() and its variants. I know that the glyphs I'm trying to retrieve are stored in the array: the dependent module simply can't access them..
Here's what a typical font element might look like in the original, raw, svg file.
<glyph glyph-name="scripts.sforzato" unicode="" horiz-adv-x="219"
d="M-206.864 126.238c-8.498 -2.679 -12.964 -10.131 -12.964 -17.821c0 -6.455 3.146 -13.0777 9.696 -17.1846c1.8 -1.1369 -9.04799 1.8 139.074 -37.9895l103.026 -27.7105l71.6682 -19.279c12.269 -3.31579 22.358 -6.11053 22.358 -6.25263
c0 -0.142105 -10.089 -2.93684 -22.358 -6.25264l-71.6682 -19.2789l-103.026 -27.7105c-154.231 -41.4474 -137.132 -36.7106 -140.4 -38.8895c-5.625 -3.7263 -8.44299 -9.80721 -8.44299 -15.8892c0 -6.056 2.795 -12.113 8.396 -15.848
c3.147 -2.07201 6.077 -3.08401 9.87399 -3.08401c3.061 0 6.685 0.658005 11.442 1.94801l161.053 43.2942c228.488 61.4133 240.486 64.527 240.486 65.2851c0 0.0888996 -0.164993 0.1455 -0.164993 0.26c0 0.0702 0.0619965 0.1623 0.263 0.297099
c5.63699 3.7421 8.45499 9.80522 8.45499 15.8684c0 6.06316 -2.81799 12.1263 -8.45499 15.8684c-3.17401 2.0842 2.27299 0.521 -46.137 13.5474l-194.447 52.2947l-161.053 43.2947c-4.795 1.316 -8.506 1.94601 -11.581 1.94601
c-1.907 0 -3.57001 -0.243004 -5.093 -0.714005z" />
Here's how the calls are set up:
import music_glyphs_store from "./music_glyphs_store.js";
import * as d3 from "d3";
Then (having, at some point, loaded and parsed the raw xml strings from file):
d3.selectAll(note_glyphs.getElementsByTagName("glyph")).each(function(d, i)
var glyph_name = this.getAttribute("glyph-name");
var horiz_adv_x = this.getAttribute("horiz-adv-x");
var path = this.getAttribute("d");
music_glyphs_store.setGlyphByName(glyph_name, horiz_adv_x, path);
);
Whatever the purpose, the idea is that stored values can later be recovered using calls to the above methods. For example:
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("brace446"));
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("accidentals.natural.arrowdown"));
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("noteheads.s2slash"));
In deference to the ES6 module conventions, I later tried eliminating the duplicate ('superflous') state module wrapper (goal: better selective exposure of inner variables and functions) - but to no avail. Declaring the array root variable at window (global) scope also brings no improvement.
The motivation for all this is a migration of existing code -with conventional html inclusions- to Webpack with it's module export/import approach, thereby also leveraging node.js's strengths. While breaking a lot of previously working code, I'm optimistic about the long-term benefits..
The problem would seem to lie with the visibility/scope of dynamically allocated memory. I begin to wonder if nested arrays can be used in a diverse Webpack context at all. Am I perhaps barking up a dead tree?
javascript arrays webpack node-modules
I'd be grateful if someone could provide a working example of a nested array populated and accessible across ES6 module boundaries, that is to say with setter and (especially) getter methods called from a dependent module.
No matter which design pattern I base my attempts on, setter methods work fine but getter methods invoked across module boundaries invariably provoke the following:
TypeError: nested_array[at_whatever_depth] is undefined
I am not convinced of polluting potentially simple principles with complex examples, but here is roughly what I'm trying to do.. I'd be mega content with something simpler that actually works..
Previously, the array was populated in the same scope as the code which used it. What follows was an attempt at 'modularising' it. The code simply readies an imported music font ('glyphs') for display.
This particular example goes back to more or less where I started: a state module approach. (Others tried? The slightly more advanced basket and revealing module, and a lot of variations thereon..).
var music_glyphs_store = (function ()
var pub = ;
pub.state = [],
pub.setGlyphByName = function (glyph_name, horiz_adv_x, path)
pub.state.push(glyph_name);
pub.state[glyph_name] = [];
pub.state[glyph_name]["glyph_name"] = glyph_name;
pub.state[glyph_name]["horiz-adv-x"] = horiz_adv_x;
pub.state[glyph_name]["d"] = path;
,
pub.getGlyphByName = function(glyph_name)
return pub.state[glyph_name];
return pub; // expose externally
)();
export music_glyphs_store ;
The problematic call is to music_glyphs_store.getGlyphByName() and its variants. I know that the glyphs I'm trying to retrieve are stored in the array: the dependent module simply can't access them..
Here's what a typical font element might look like in the original, raw, svg file.
<glyph glyph-name="scripts.sforzato" unicode="" horiz-adv-x="219"
d="M-206.864 126.238c-8.498 -2.679 -12.964 -10.131 -12.964 -17.821c0 -6.455 3.146 -13.0777 9.696 -17.1846c1.8 -1.1369 -9.04799 1.8 139.074 -37.9895l103.026 -27.7105l71.6682 -19.279c12.269 -3.31579 22.358 -6.11053 22.358 -6.25263
c0 -0.142105 -10.089 -2.93684 -22.358 -6.25264l-71.6682 -19.2789l-103.026 -27.7105c-154.231 -41.4474 -137.132 -36.7106 -140.4 -38.8895c-5.625 -3.7263 -8.44299 -9.80721 -8.44299 -15.8892c0 -6.056 2.795 -12.113 8.396 -15.848
c3.147 -2.07201 6.077 -3.08401 9.87399 -3.08401c3.061 0 6.685 0.658005 11.442 1.94801l161.053 43.2942c228.488 61.4133 240.486 64.527 240.486 65.2851c0 0.0888996 -0.164993 0.1455 -0.164993 0.26c0 0.0702 0.0619965 0.1623 0.263 0.297099
c5.63699 3.7421 8.45499 9.80522 8.45499 15.8684c0 6.06316 -2.81799 12.1263 -8.45499 15.8684c-3.17401 2.0842 2.27299 0.521 -46.137 13.5474l-194.447 52.2947l-161.053 43.2947c-4.795 1.316 -8.506 1.94601 -11.581 1.94601
c-1.907 0 -3.57001 -0.243004 -5.093 -0.714005z" />
Here's how the calls are set up:
import music_glyphs_store from "./music_glyphs_store.js";
import * as d3 from "d3";
Then (having, at some point, loaded and parsed the raw xml strings from file):
d3.selectAll(note_glyphs.getElementsByTagName("glyph")).each(function(d, i)
var glyph_name = this.getAttribute("glyph-name");
var horiz_adv_x = this.getAttribute("horiz-adv-x");
var path = this.getAttribute("d");
music_glyphs_store.setGlyphByName(glyph_name, horiz_adv_x, path);
);
Whatever the purpose, the idea is that stored values can later be recovered using calls to the above methods. For example:
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("brace446"));
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("accidentals.natural.arrowdown"));
console.log("index.js: Recovering " + music_glyphs_store.getGlyphByName("noteheads.s2slash"));
In deference to the ES6 module conventions, I later tried eliminating the duplicate ('superflous') state module wrapper (goal: better selective exposure of inner variables and functions) - but to no avail. Declaring the array root variable at window (global) scope also brings no improvement.
The motivation for all this is a migration of existing code -with conventional html inclusions- to Webpack with it's module export/import approach, thereby also leveraging node.js's strengths. While breaking a lot of previously working code, I'm optimistic about the long-term benefits..
The problem would seem to lie with the visibility/scope of dynamically allocated memory. I begin to wonder if nested arrays can be used in a diverse Webpack context at all. Am I perhaps barking up a dead tree?
javascript arrays webpack node-modules
javascript arrays webpack node-modules
edited Mar 24 at 21:07
user1019696
asked Mar 21 at 15:54
user1019696user1019696
1701312
1701312
1
Arrays usually do not have "setter" or "getter" methods. Without seeing the code involved, I doubt anybody will figure out the problem.
– Pointy
Mar 21 at 15:55
setter + getter wrapper functions. If I post code, it would just be one of many unsuccessful attempts. I'd prefer, where possible, to see a proven example.
– user1019696
Mar 21 at 15:58
1
It's not even clear what you mean by "nested array"; if you export a reference to an object of any kind, an importing module has access to the entire object graph.
– Pointy
Mar 21 at 16:17
Don't abuse arrays when you need objects
– Bergi
Mar 23 at 14:33
Please post the code that imports your module and uses themusic_glyphs_store
object so that we have a Minimal, Complete, and Verifiable example of what doesn't work.
– Bergi
Mar 23 at 14:35
add a comment |
1
Arrays usually do not have "setter" or "getter" methods. Without seeing the code involved, I doubt anybody will figure out the problem.
– Pointy
Mar 21 at 15:55
setter + getter wrapper functions. If I post code, it would just be one of many unsuccessful attempts. I'd prefer, where possible, to see a proven example.
– user1019696
Mar 21 at 15:58
1
It's not even clear what you mean by "nested array"; if you export a reference to an object of any kind, an importing module has access to the entire object graph.
– Pointy
Mar 21 at 16:17
Don't abuse arrays when you need objects
– Bergi
Mar 23 at 14:33
Please post the code that imports your module and uses themusic_glyphs_store
object so that we have a Minimal, Complete, and Verifiable example of what doesn't work.
– Bergi
Mar 23 at 14:35
1
1
Arrays usually do not have "setter" or "getter" methods. Without seeing the code involved, I doubt anybody will figure out the problem.
– Pointy
Mar 21 at 15:55
Arrays usually do not have "setter" or "getter" methods. Without seeing the code involved, I doubt anybody will figure out the problem.
– Pointy
Mar 21 at 15:55
setter + getter wrapper functions. If I post code, it would just be one of many unsuccessful attempts. I'd prefer, where possible, to see a proven example.
– user1019696
Mar 21 at 15:58
setter + getter wrapper functions. If I post code, it would just be one of many unsuccessful attempts. I'd prefer, where possible, to see a proven example.
– user1019696
Mar 21 at 15:58
1
1
It's not even clear what you mean by "nested array"; if you export a reference to an object of any kind, an importing module has access to the entire object graph.
– Pointy
Mar 21 at 16:17
It's not even clear what you mean by "nested array"; if you export a reference to an object of any kind, an importing module has access to the entire object graph.
– Pointy
Mar 21 at 16:17
Don't abuse arrays when you need objects
– Bergi
Mar 23 at 14:33
Don't abuse arrays when you need objects
– Bergi
Mar 23 at 14:33
Please post the code that imports your module and uses the
music_glyphs_store
object so that we have a Minimal, Complete, and Verifiable example of what doesn't work.– Bergi
Mar 23 at 14:35
Please post the code that imports your module and uses the
music_glyphs_store
object so that we have a Minimal, Complete, and Verifiable example of what doesn't work.– Bergi
Mar 23 at 14:35
add a comment |
2 Answers
2
active
oldest
votes
I think you are confusing array and objects. Arrays are sequential lists, where the index of each cell is an integer. Your code is pushing glyph_name and unicode onto the state array, which places it in next element in the array, but then you are referencing the array using glyph_name and unicode as the index. I think you want to be using objects instead of arrays. Change the lines:
pub.state = [];
pub.state[glyph_name] = [];
pub.state[unicode] = [];
to
pub.state = ;
pub.state[glyph_name] = ;
pub.state[unicode] = ;
This proved correct in the long run (my code constellation is a little more complex that shown in the original question, and I made a mistake in the tests targeting your suggestions.
– user1019696
Mar 24 at 20:47
add a comment |
Though incorrect, I'm leaving this answer in place to illustrate what (as pointed out by @Bergi in the comments) qualifies as "array abuse".
The consistently unsettling thing here was that the original code worked fine. It only broke on integration to Webpack. That suggested that structurally, things may be more or less ok, but that in the earlier implementation, there were likely related problems.
With a little experiment, I found I could successfully retrieve array values across module boundaries by enclosing glyph_name
in rounded brackets. For example:
pub.getGlyphByName = function(glyph_name)
return pub.state[(glyph_name)];
,
BUT 1) I don't entirely understand what is happening, and 2) it looks fragile..
The actual (external, dependent module) call would remain as in the original question.
--> Immediate problem solved, but only by abusing the arrays..
"unicode values used to establish an array key are automatically converted to some form of textual value" - yes, all property names are strings, and any value is coerced to one. "something similar occurs during retrieval if the unicode value is wrapped in rounded brackets" - no. The parenthesis change absolutely nothing in functionality. (If they did, it's a bug in the engine or toolchain that you are using).
– Bergi
Mar 23 at 14:39
@Bergi - You are right. If I use unicodes, the parentheses have no effect. Using glyph_name (with parenthesis), however, the calls are working across module boundaries. This is an improvement, even if I don't quite understand why.
– user1019696
Mar 23 at 15:41
For clarity (minimal/complete/verifiable), I see I will need to remove pretty much all reference to unicodes. This is likely to invalidate some comments.
– user1019696
Mar 23 at 15:54
The comments are still valid. Given you didn't present any examples of how you are calling the methods, I have no idea what you meant by "glyphs" or "unicodes" anyway.
– Bergi
Mar 23 at 18:06
I suspect the reason unicode values were used in the original implementation was that this is the 'standard' way of identifying / referencing music glyphs (symbols). I strongly suspect glyph names can vary across music font implementations.
– user1019696
Mar 23 at 19:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284422%2fnested-javascript-arrays-access-across-module-boundaries%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you are confusing array and objects. Arrays are sequential lists, where the index of each cell is an integer. Your code is pushing glyph_name and unicode onto the state array, which places it in next element in the array, but then you are referencing the array using glyph_name and unicode as the index. I think you want to be using objects instead of arrays. Change the lines:
pub.state = [];
pub.state[glyph_name] = [];
pub.state[unicode] = [];
to
pub.state = ;
pub.state[glyph_name] = ;
pub.state[unicode] = ;
This proved correct in the long run (my code constellation is a little more complex that shown in the original question, and I made a mistake in the tests targeting your suggestions.
– user1019696
Mar 24 at 20:47
add a comment |
I think you are confusing array and objects. Arrays are sequential lists, where the index of each cell is an integer. Your code is pushing glyph_name and unicode onto the state array, which places it in next element in the array, but then you are referencing the array using glyph_name and unicode as the index. I think you want to be using objects instead of arrays. Change the lines:
pub.state = [];
pub.state[glyph_name] = [];
pub.state[unicode] = [];
to
pub.state = ;
pub.state[glyph_name] = ;
pub.state[unicode] = ;
This proved correct in the long run (my code constellation is a little more complex that shown in the original question, and I made a mistake in the tests targeting your suggestions.
– user1019696
Mar 24 at 20:47
add a comment |
I think you are confusing array and objects. Arrays are sequential lists, where the index of each cell is an integer. Your code is pushing glyph_name and unicode onto the state array, which places it in next element in the array, but then you are referencing the array using glyph_name and unicode as the index. I think you want to be using objects instead of arrays. Change the lines:
pub.state = [];
pub.state[glyph_name] = [];
pub.state[unicode] = [];
to
pub.state = ;
pub.state[glyph_name] = ;
pub.state[unicode] = ;
I think you are confusing array and objects. Arrays are sequential lists, where the index of each cell is an integer. Your code is pushing glyph_name and unicode onto the state array, which places it in next element in the array, but then you are referencing the array using glyph_name and unicode as the index. I think you want to be using objects instead of arrays. Change the lines:
pub.state = [];
pub.state[glyph_name] = [];
pub.state[unicode] = [];
to
pub.state = ;
pub.state[glyph_name] = ;
pub.state[unicode] = ;
answered Mar 21 at 19:18
jalynn2jalynn2
4,82911114
4,82911114
This proved correct in the long run (my code constellation is a little more complex that shown in the original question, and I made a mistake in the tests targeting your suggestions.
– user1019696
Mar 24 at 20:47
add a comment |
This proved correct in the long run (my code constellation is a little more complex that shown in the original question, and I made a mistake in the tests targeting your suggestions.
– user1019696
Mar 24 at 20:47
This proved correct in the long run (my code constellation is a little more complex that shown in the original question, and I made a mistake in the tests targeting your suggestions.
– user1019696
Mar 24 at 20:47
This proved correct in the long run (my code constellation is a little more complex that shown in the original question, and I made a mistake in the tests targeting your suggestions.
– user1019696
Mar 24 at 20:47
add a comment |
Though incorrect, I'm leaving this answer in place to illustrate what (as pointed out by @Bergi in the comments) qualifies as "array abuse".
The consistently unsettling thing here was that the original code worked fine. It only broke on integration to Webpack. That suggested that structurally, things may be more or less ok, but that in the earlier implementation, there were likely related problems.
With a little experiment, I found I could successfully retrieve array values across module boundaries by enclosing glyph_name
in rounded brackets. For example:
pub.getGlyphByName = function(glyph_name)
return pub.state[(glyph_name)];
,
BUT 1) I don't entirely understand what is happening, and 2) it looks fragile..
The actual (external, dependent module) call would remain as in the original question.
--> Immediate problem solved, but only by abusing the arrays..
"unicode values used to establish an array key are automatically converted to some form of textual value" - yes, all property names are strings, and any value is coerced to one. "something similar occurs during retrieval if the unicode value is wrapped in rounded brackets" - no. The parenthesis change absolutely nothing in functionality. (If they did, it's a bug in the engine or toolchain that you are using).
– Bergi
Mar 23 at 14:39
@Bergi - You are right. If I use unicodes, the parentheses have no effect. Using glyph_name (with parenthesis), however, the calls are working across module boundaries. This is an improvement, even if I don't quite understand why.
– user1019696
Mar 23 at 15:41
For clarity (minimal/complete/verifiable), I see I will need to remove pretty much all reference to unicodes. This is likely to invalidate some comments.
– user1019696
Mar 23 at 15:54
The comments are still valid. Given you didn't present any examples of how you are calling the methods, I have no idea what you meant by "glyphs" or "unicodes" anyway.
– Bergi
Mar 23 at 18:06
I suspect the reason unicode values were used in the original implementation was that this is the 'standard' way of identifying / referencing music glyphs (symbols). I strongly suspect glyph names can vary across music font implementations.
– user1019696
Mar 23 at 19:51
add a comment |
Though incorrect, I'm leaving this answer in place to illustrate what (as pointed out by @Bergi in the comments) qualifies as "array abuse".
The consistently unsettling thing here was that the original code worked fine. It only broke on integration to Webpack. That suggested that structurally, things may be more or less ok, but that in the earlier implementation, there were likely related problems.
With a little experiment, I found I could successfully retrieve array values across module boundaries by enclosing glyph_name
in rounded brackets. For example:
pub.getGlyphByName = function(glyph_name)
return pub.state[(glyph_name)];
,
BUT 1) I don't entirely understand what is happening, and 2) it looks fragile..
The actual (external, dependent module) call would remain as in the original question.
--> Immediate problem solved, but only by abusing the arrays..
"unicode values used to establish an array key are automatically converted to some form of textual value" - yes, all property names are strings, and any value is coerced to one. "something similar occurs during retrieval if the unicode value is wrapped in rounded brackets" - no. The parenthesis change absolutely nothing in functionality. (If they did, it's a bug in the engine or toolchain that you are using).
– Bergi
Mar 23 at 14:39
@Bergi - You are right. If I use unicodes, the parentheses have no effect. Using glyph_name (with parenthesis), however, the calls are working across module boundaries. This is an improvement, even if I don't quite understand why.
– user1019696
Mar 23 at 15:41
For clarity (minimal/complete/verifiable), I see I will need to remove pretty much all reference to unicodes. This is likely to invalidate some comments.
– user1019696
Mar 23 at 15:54
The comments are still valid. Given you didn't present any examples of how you are calling the methods, I have no idea what you meant by "glyphs" or "unicodes" anyway.
– Bergi
Mar 23 at 18:06
I suspect the reason unicode values were used in the original implementation was that this is the 'standard' way of identifying / referencing music glyphs (symbols). I strongly suspect glyph names can vary across music font implementations.
– user1019696
Mar 23 at 19:51
add a comment |
Though incorrect, I'm leaving this answer in place to illustrate what (as pointed out by @Bergi in the comments) qualifies as "array abuse".
The consistently unsettling thing here was that the original code worked fine. It only broke on integration to Webpack. That suggested that structurally, things may be more or less ok, but that in the earlier implementation, there were likely related problems.
With a little experiment, I found I could successfully retrieve array values across module boundaries by enclosing glyph_name
in rounded brackets. For example:
pub.getGlyphByName = function(glyph_name)
return pub.state[(glyph_name)];
,
BUT 1) I don't entirely understand what is happening, and 2) it looks fragile..
The actual (external, dependent module) call would remain as in the original question.
--> Immediate problem solved, but only by abusing the arrays..
Though incorrect, I'm leaving this answer in place to illustrate what (as pointed out by @Bergi in the comments) qualifies as "array abuse".
The consistently unsettling thing here was that the original code worked fine. It only broke on integration to Webpack. That suggested that structurally, things may be more or less ok, but that in the earlier implementation, there were likely related problems.
With a little experiment, I found I could successfully retrieve array values across module boundaries by enclosing glyph_name
in rounded brackets. For example:
pub.getGlyphByName = function(glyph_name)
return pub.state[(glyph_name)];
,
BUT 1) I don't entirely understand what is happening, and 2) it looks fragile..
The actual (external, dependent module) call would remain as in the original question.
--> Immediate problem solved, but only by abusing the arrays..
edited Mar 24 at 23:29
E_net4
12.8k73872
12.8k73872
answered Mar 23 at 14:25
user1019696user1019696
1701312
1701312
"unicode values used to establish an array key are automatically converted to some form of textual value" - yes, all property names are strings, and any value is coerced to one. "something similar occurs during retrieval if the unicode value is wrapped in rounded brackets" - no. The parenthesis change absolutely nothing in functionality. (If they did, it's a bug in the engine or toolchain that you are using).
– Bergi
Mar 23 at 14:39
@Bergi - You are right. If I use unicodes, the parentheses have no effect. Using glyph_name (with parenthesis), however, the calls are working across module boundaries. This is an improvement, even if I don't quite understand why.
– user1019696
Mar 23 at 15:41
For clarity (minimal/complete/verifiable), I see I will need to remove pretty much all reference to unicodes. This is likely to invalidate some comments.
– user1019696
Mar 23 at 15:54
The comments are still valid. Given you didn't present any examples of how you are calling the methods, I have no idea what you meant by "glyphs" or "unicodes" anyway.
– Bergi
Mar 23 at 18:06
I suspect the reason unicode values were used in the original implementation was that this is the 'standard' way of identifying / referencing music glyphs (symbols). I strongly suspect glyph names can vary across music font implementations.
– user1019696
Mar 23 at 19:51
add a comment |
"unicode values used to establish an array key are automatically converted to some form of textual value" - yes, all property names are strings, and any value is coerced to one. "something similar occurs during retrieval if the unicode value is wrapped in rounded brackets" - no. The parenthesis change absolutely nothing in functionality. (If they did, it's a bug in the engine or toolchain that you are using).
– Bergi
Mar 23 at 14:39
@Bergi - You are right. If I use unicodes, the parentheses have no effect. Using glyph_name (with parenthesis), however, the calls are working across module boundaries. This is an improvement, even if I don't quite understand why.
– user1019696
Mar 23 at 15:41
For clarity (minimal/complete/verifiable), I see I will need to remove pretty much all reference to unicodes. This is likely to invalidate some comments.
– user1019696
Mar 23 at 15:54
The comments are still valid. Given you didn't present any examples of how you are calling the methods, I have no idea what you meant by "glyphs" or "unicodes" anyway.
– Bergi
Mar 23 at 18:06
I suspect the reason unicode values were used in the original implementation was that this is the 'standard' way of identifying / referencing music glyphs (symbols). I strongly suspect glyph names can vary across music font implementations.
– user1019696
Mar 23 at 19:51
"unicode values used to establish an array key are automatically converted to some form of textual value" - yes, all property names are strings, and any value is coerced to one. "something similar occurs during retrieval if the unicode value is wrapped in rounded brackets" - no. The parenthesis change absolutely nothing in functionality. (If they did, it's a bug in the engine or toolchain that you are using).
– Bergi
Mar 23 at 14:39
"unicode values used to establish an array key are automatically converted to some form of textual value" - yes, all property names are strings, and any value is coerced to one. "something similar occurs during retrieval if the unicode value is wrapped in rounded brackets" - no. The parenthesis change absolutely nothing in functionality. (If they did, it's a bug in the engine or toolchain that you are using).
– Bergi
Mar 23 at 14:39
@Bergi - You are right. If I use unicodes, the parentheses have no effect. Using glyph_name (with parenthesis), however, the calls are working across module boundaries. This is an improvement, even if I don't quite understand why.
– user1019696
Mar 23 at 15:41
@Bergi - You are right. If I use unicodes, the parentheses have no effect. Using glyph_name (with parenthesis), however, the calls are working across module boundaries. This is an improvement, even if I don't quite understand why.
– user1019696
Mar 23 at 15:41
For clarity (minimal/complete/verifiable), I see I will need to remove pretty much all reference to unicodes. This is likely to invalidate some comments.
– user1019696
Mar 23 at 15:54
For clarity (minimal/complete/verifiable), I see I will need to remove pretty much all reference to unicodes. This is likely to invalidate some comments.
– user1019696
Mar 23 at 15:54
The comments are still valid. Given you didn't present any examples of how you are calling the methods, I have no idea what you meant by "glyphs" or "unicodes" anyway.
– Bergi
Mar 23 at 18:06
The comments are still valid. Given you didn't present any examples of how you are calling the methods, I have no idea what you meant by "glyphs" or "unicodes" anyway.
– Bergi
Mar 23 at 18:06
I suspect the reason unicode values were used in the original implementation was that this is the 'standard' way of identifying / referencing music glyphs (symbols). I strongly suspect glyph names can vary across music font implementations.
– user1019696
Mar 23 at 19:51
I suspect the reason unicode values were used in the original implementation was that this is the 'standard' way of identifying / referencing music glyphs (symbols). I strongly suspect glyph names can vary across music font implementations.
– user1019696
Mar 23 at 19:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284422%2fnested-javascript-arrays-access-across-module-boundaries%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Arrays usually do not have "setter" or "getter" methods. Without seeing the code involved, I doubt anybody will figure out the problem.
– Pointy
Mar 21 at 15:55
setter + getter wrapper functions. If I post code, it would just be one of many unsuccessful attempts. I'd prefer, where possible, to see a proven example.
– user1019696
Mar 21 at 15:58
1
It's not even clear what you mean by "nested array"; if you export a reference to an object of any kind, an importing module has access to the entire object graph.
– Pointy
Mar 21 at 16:17
Don't abuse arrays when you need objects
– Bergi
Mar 23 at 14:33
Please post the code that imports your module and uses the
music_glyphs_store
object so that we have a Minimal, Complete, and Verifiable example of what doesn't work.– Bergi
Mar 23 at 14:35