zanethomas
Joined 12 years ago
Joined 12 years ago
I really like the flexibility of factory functions, that is the main point of the article imo.
COM/OLE ... that takes me back to the early 90s, a place I hoped to never visit again!
:)
emulating classes is, imo, exactly the problem
using factory functions which create and return an object, with variables passed to and created in the function, handles encapsulation
and there is no `this` to deal with
makeThing(options, usethistoo) { let foo = options.foo; let thistoo = usethistoo;
return {
functions...
}
}I started with 6800 machine language. Then c, smalltalk, scheme and etc.
Rather than spend a lot of time and botch a comparison between classes and factory functions I'll link you to an article.
He went further, introducing something he calls stamps, but I found them to be awkward the only time I tried to use them.
https://medium.com/javascript-scene/javascript-factory-funct...
Sometimes programmers spend way too much time optimizing code which doesn't really need it.
In my experience how data is structured is almost always the most important factor when it comes to performance.
Good data structure + simple code === performance.
Fortunately we can still aren't forced to use all the 'enhancements'.
Class is entirely unnecessary and, essentially, tries to turn JS into a class-oriented language from its core which is object-oriented.
I never create classes. I always create factory functions which, when appropriate, can accept other objects for composition.
And I don't use prototypes, because they are unnecessary as well. Thus sparing me the inconvenience, and potential issues, of using 'this'.
In my dreams those who want to turn JS into c# or Java should just create a language they like and stop piling on to JS.
But, at least so far, the core of JS has not been ruined.
That said, there are some new features I like. Promises/async/await, Map, Set, enhancements to Array being among them. But to my way of thinking they do not change the nature of the language in any way.
Regardless, well done!