I am running a project with webpack and faced a problem. I solved it but I want to understand how the things are working.
I have an array with module names like [module1,module2,module3]
.
I use foreach
to loop this array and import every module with following syntax.
import('./' + moduleName).then(function (promise) {
var me = promise.default(element);
})
In every module I create and return object "me" .Every module has specific functionality and parameters which aren't important for the question.
export default function (element, options) {
var me = this;
// some other code
return me;
}
The problem occurs when I have 2 some modules on one page. The assignment me = this, somehow always create same object with same parameters even when I pass different options.
I solved it by changing the assignment to var me = Object.assign({},this);
But I don't understand what is wrong with the first one.
Can you give me some explanation?