Does (function() {})(); affect Imported Variables?

I noticed that when I do a (function() {})() and put all the elements inside the {} and get out of there to declare imported values, it says some of the variables are unreadable. What's the proper way of using Imported together with (function() {})()?
What do you mean with Imported Variables?
I did make import function outside the (function() {})(), namely:

var Imported = Imported || {};Imported.Milena= true;var firstplugin = Milena|| {};firstplugin .Milena = {};and added variables that makes its value to the params. Somehow it says its having an error when you put or assign them again side the function.
Anything you declare outside the anonymous function can be access both inside and outside.

Anything you declare inside it, can only be used inside it.

Try running this and you'll understand:

Code:
var Imported = Imported || {}; (function(){  Imported.Something = true;   var localVariable = 15;})(); console.log(Imported);console.log(localVariable);
Anything you declare outside the anonymous function can be access both inside and outside.

Anything you declare inside it, can only be used inside it.

Try running this and you'll understand:

var Imported = Imported || {}; (function(){  Imported.Something = true;   var localVariable = 15;})(); console.log(Imported);console.log(localVariable);
But isn't that completely independant from this 'anonymous' function?

Anything declared with 'var' inside a function is private and can't be read from the outside, that should have nothing to do with whatever

(function(){

})();

actually does right?
Yes.

This:

(function(){  var localVariable = 15;}();
is the same thing as this:

function doSomething() {  var localVariable = 15;} doSomething();
The localVariable won't exist outside the function.
Yes.

This:

(function(){  var localVariable = 15;}();is the same thing as this:

function doSomething() {  var localVariable = 15;} doSomething();The localVariable won't exist outside the function.

So for better understanding of that construct...

Does that mean its a self...calling/executing function?

So the

(function(){

})();

part calls the function o n its own?

Or is it simply just some shortend/different way to type a function?
Yes, the bolded part is executing the function.

It's the same as doing this:

Code:
var x = (function(){  // do something}); x();
(function(){
})();

This is an immediately executed function. The () at the end is the code that executes the function you've created there at the time it was created 🙂
Well cool, so like I thought.

Just wondering cause I kept hearing 'anonymous' associated to that construct, but that has nothing to do with it after all, its just the way defined variables work in JS.

If you do write plugins like that, is there even a need to pass them along to the plugin manager then?

Still figuring out how MV flows, where it starts and so on.

I can read the code now, most of it anyways, but finding your starting point is still pretty hard 🤣
Gosh, it seems there's so much to learn. :/
I personally create everything inside a module so that its all scoped, of course global RPG Maker Stuff isn't scoped to my module but thats ok. How ever all the classes, all the methods and all that jazz that I write is scoped.

Original thread: https://forums.rpgmakerweb.com/threads/does-function-affect-imported-variables.50593/