In my applications, I'm not sure if I duplicate data when I pass it to other objects. As an example, look at the following code:
var DataStore = function(data) { this.data = data; // <-- typeof data === 'object' } var Controller = function() { var dataStore = new DataStore({foo: 'bar'}); var plugin = new Plugin(dataStore.data); } var Plugin = function(data) { this.data = data; } var app = new Controller();
When I create the plugin, the data property from dataStore is passed to it. Then it is assigned to the property inside the plugin. Bearing in mind that the transmitted data is an object, to my question, is this the creation of two variables in memory, or is the data property in the plugin referencing a property in the DataStore object?
If it does not save the link after the assignment, how can I pass the DataStore to plugins and save the link to it locally? Or do I need to save the DataStore as a global variable in my application area and reference it globally from plugins?
source share