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.
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.