Recent submissions

Comment · 2 years ago
The difference in performance is negligible for all but the most demanding applications. In which case I would still use factory functions, but just be more careful.
Comment · 2 years ago
Fair points. I do use classes exposed by libraries. I don't like it but it beats the alternative.

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!

:)

Comment · 2 years ago
closures can encapsulate state and methods classes are syntactic sugar

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

Comment · 2 years ago
Does it compile something like this into a c++ class?

makeThing(options, usethistoo) { let foo = options.foo; let thistoo = usethistoo;

  return {
    functions...
  }
}
Comment · 2 years ago
Comment · 2 years ago
I wonder why it seems natural to you? I'm guessing JS wasn't your first language and you didn't learn the power of composition instead of classes.
Comment · 2 years ago
Sure, but imo unless one is creating very many objects each with their own set of functions it's not really a significant issue.

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.

Comment · 2 years ago
I know, right?

Fortunately we can still aren't forced to use all the 'enhancements'.

Comment · 2 years ago
I don't understand the need for the ever-growing list of "enhancements" to JS. Take Class for example.

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.

Comment · 2 years ago
The web became trashed over a decade ago.
Comment · 2 years ago
The web became trashed over a decade ago.
Comment · 2 years ago
Because they chose it as a career and not because they love it?
Comment · 2 years ago
Hmmm, odd. I was under the impression they used cosine similarity based on page content. Once upon a time, based on that 'memory', I created a system to bin domain names into categories using cosine similarity. It worked surprising well.

Regardless, well done!

Comment · 2 years ago
Isn't that Google's original algorithm?
Comment · 3 years ago
Don't use it, don't care.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton