Re:The use of `class` for things that should be simple free ...
by amw-zero on Thursday May 28, 2020 @11:41AM
(#23338599)
I will definitely admit that those numbers are made up, more of a rhetorical technique. Numbers are important, I do agree.
Re:The use of `class` for things that should be simple free ...
by fendy3002 on Thursday May 28, 2020 @12:05PM
(#23338890)
For JS, it's best to avoid class as possible, due to this and bind / apply shenanigans.
Closure and function return function can be used as substitute, and except for inheritance (which should be avoided too), I haven't found any use case for using class class. Example:
function MyList {
let data = [];
let add = (item) => data.push(item);
return { add };
}
Re:The use of `class` for things that should be simple free ...
by nonsense1234 on Thursday May 28, 2020 @12:47PM
(#23339452)
> Closure and function return function can be used as substitute
So for every list you have an additional allocation for the add function. It obviously continuously to get much worse as more "methods" are inevitably added. That's extremely inefficient for something that's used often and it's not something JavaScript engines can optimize away. The benefit is also extremely negligible since the closed over values are still implicit in the call to add.
I'm noting this because i think that number kinda detracts from your main argument, with which i agree completely. I think even if the code would remain roughly the same size, the removal of OO would still be worth it, since, as you mention, is much less jargon and conceptual baggage. And if i can achieve the same result with a much simpler conceptual model and language, then all the better :)