Currently, I am developing classes in ES6 modules using object literals and my intention is to update object attributes within a function. Although modules run in strict mode by default which ensures safe usage of this
, I am uncertain whether calling the function foo()
will modify the object in the main script file or if it only affects the local object within Controller.mjs
. Will both function calls produce the same outcome?
//Controller.mjs
const Controller = {
someAttr1: [],
someAttr2: true,
foo: function () {
this.someAttr1.push("some value");
Controller.someAttr1.push("some value");
}
};
//export Controller's interface...
//SomeOtherFile.mjs
import { Controller } from 'Controller.mjs'
Controller.foo();