-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Hello everyone!
I'm investigating the means of fully transitioning p5 to ES6. I've already spoken to some of the developers outside of Github and was hoping to shine some light on some of the intricacies that I've observed in the code.
I've noticed there are 42 instances of module.exports = p5; in the bundled .js files. And I hope this issue serves as a clarification of the assumption that I have:
From what I understand each module.exports = p5; is effectively exposing p5 after extending it in its own respected files/module, be it curves.js, vertex.js, etc.
Although what seems to be the case is that most modules usually inherit/require from main.js, there are few instances of sequential inheritance of p5.
For instance:
In string_functions.js we have:
var p5 = require('../core/main');
require('../core/error_helpers');
....
module.exports = p5;
Both main and error_helpers have their own respective modules.exports = p5. However string_functions is exporting the instance of p5 inheritted from main.
My question in regards to this specific instance is by the end of string_functions when we are exporting p5, will this instance have all the prototypal functions defined in error_helpers?
From my understanding, the inheritance scheme seems to be a directed acyclical graph with a single root node (main.js - A in picture) and a single leaf node which is p5 at its final stage after all the additions to the prototype occur in multiple files ( F in picture or equivalently p5() in browser).
I know javascript is independent of the order the code is written unlike C++, and instances and references are resolved during JIT. Given that there are 42 instances of module.exports=p5 in the bundled lib, how is each instance resolved properly? Is each instance unique, with functionalities unavailable in preceding exports or do they all refer to the same class for lack of a better word?
Moreover given the import syntax in ES6, how does this export/require paradigm change, if it does?
Apologies in advance if these questions seem trivial or show a lack of knowledge in JS. I come from different programming languages and JS seems like wild west to me!
Edit: I'm unable to appropriately label my issue. I assume it should be considered a "discussion".
