immutability in JS im important

Regardless of how you program your scripts, weather they be in classes in or prototype objects you need to take into consideration that people will either by there own doing or not create "global" variables and objects which are easy to mutate and cause issues as more and more scripts are added to a game.

A very common practice in JS programming is the concept of immutability: http://www.sitepoint.com/immutability-javascript/

Which I suggest you do some research on.

Immutability basically allows me to create a common state of variables. object or what have you and the end result would be a setState() which based function that basically updates the current state of the object.

React JS is a good example of this.

Lets assume you have the concept of a dog that barks, well you would not update the dog directly to meow, you would update a state of the dog to meow thus allowing you to call the original dog object and get bark.

Immutability in these types of scripts is crucial because if bob creates a variable or state object and directly update it in my script then his script breaks and I come to the forums wondering why bob sucks at programming when in fact the error is on me.

With immutability, bob creates a script and I call things like setState, updateObject or what have you. to change the values of his script with out breaking things.

I would love to start a discussion on this as the concept of self executing javascript can cause mutation issues and cause scripts to not properly work.

People have pointed out to me, and this is interesting, the concept of aliasing methods in prototyping, but I feel that as your scripts grow its harder to modularize and keep in your head, should I mutate x directly or indirectly (hint the answer is never, you don't mutate anything directly or indirectly, you update it and check that against the old and then update the "scene" with the new) 

Now I don't believe in using prototypes unless I am registering something, so there will for sure be some concepts I have yet to learn, my senior level of experience comes from the face that I create class based objects and even, when I get a chance, classes in ES6. So please - do teach - .

What are your thoughts on immutability with JS and how would you like to see it implemented in scripts? 

Disclamer:

This is not a "we should have this type of template for this concept, this is a discussion amongst people who understand the concept of immutability and a place for people who are not familiar with this to ask questions.

Also I have described immutability the way I use it: nothing changes anything directly, things are updated, checked and refreshed.

And discuss.
I'm not sure I understand. So these are just using setters and getters to interact with objects rather than directly accessing them?


I can see from the article that it returns a copy of some property when you ask for it, so you don't accidentally go and mutate it, but from the sounds of it you are advocating the use of immutability for everything.

With immutability, bob creates a script and I call things like setState, updateObject or what have you. to change the values of his script with out breaking things.
Can you provide examples of how you would break things if you were not using those methods?
I don't know if you actually know how people handle scripts here.

We can't make default classes inmutable, that would make pointless the idea of an extension, because you can't extend inmutable objects.

We actually archive the idea using a simple, yet usefull Imported variable, where you can check if another script is working there or not.

We won't make our classes frozen, because we want to extend, not evade extensions.

Your own classes should be in your module, so there is less chance to conflict with other.

Inmutability works on big projects or engines that needs some performance improvements (wich in javascript usually don't apply on all virtual machines)

While you can extend objects by another methods, like composition (wich would mean your objects insn't inmmutable, because you can add or remove things to it), the maker by default never helped us in that regard.

the state pattern works sometimes, the battle engine and the maps and the menu probably using it, but there are things like actor thatn you have no other way to change if you are not changing the original object =/
Closed due to OP's request.

Original thread: https://forums.rpgmakerweb.com/threads/immutability-in-js-im-important.45829/