I recently watched a youtube tutorial, and the guy did something interesting in the series (it's node.js game tutorials by Raining Chain). His constructor looks like this:
const MakeStuff = function(param1, param2) {
const self = {};
self._param1 = param1;
self._param2 = param2;
// and so on...
return self;
}
const someStuff = MakeStuff(param1, param2);
I then checked google for what "self" meant and it found out it's something similar to "this"... It's really confusing me now. At first I thought he's just naming it "self" to mimic "this", but avoid using it.
Also, JSLint really hates "this", and I hate to dumb down JSLint and disable or edit options (ocd), so I'm trying to figure out how am I gonna use classes, and avoid using "this" inside classes constructor.
I figured I'd copy/paste my class function in babeljs and see what the class syntax actually does under the hood, but I got even more confused.
I have around 2k lines of code in my game, and 1.5k are just classes with getters, setters and static methods.
What does the code above actually do? What does self mean? Can I use JS classes and avoid using "this" in constructors? Why does JSLint even hate "this"? Should I rework my code using the example above and bind getters, setters and static methods using prototype?
Thanks!