Live data from Hacker News

How Does React Tell a Class from a Function?

overreacted.io

21–30 of 142 posts

Re: How Does React Tell a Class from a Function?

#22
post #17

I have written maybe 200 lines of JavaScript in my life, and this article has strongly reinforced my desire to never have to write a single one more. The next time someone asks me what the problem with JavaScript is, I will send them this article. "Scheme for the browser" what a joke. Some excerpts for those that didn't have the strength to sit through the entire thing without pulling their hair out: > If you called…

One of the points of the post was that you almost definitely don't need to worry about this yourself, especially if you're using React.

If you're going to be using any language seriously, you better understand how functions and objects and classes in that language work.

Re: How Does React Tell a Class from a Function?

#24
post #22

Earlier quoted context omitted.

One of the points of the post was that you almost definitely don't need to worry about this yourself, especially if you're using React.

If you're going to be using any language seriously, you better understand how functions and objects and classes in that language work.

[deleted]

Re: How Does React Tell a Class from a Function?

#25
post #22

Earlier quoted context omitted.

One of the points of the post was that you almost definitely don't need to worry about this yourself, especially if you're using React.

If you're going to be using any language seriously, you better understand how functions and objects and classes in that language work.

I’ve been writing React for 3ish years and not once would knowing any of the weird details in the blog post have been useful for anything I’ve built.

Re: How Does React Tell a Class from a Function?

#26
post #17

I have written maybe 200 lines of JavaScript in my life, and this article has strongly reinforced my desire to never have to write a single one more. The next time someone asks me what the problem with JavaScript is, I will send them this article. "Scheme for the browser" what a joke. Some excerpts for those that didn't have the strength to sit through the entire thing without pulling their hair out: > If you called…

I've written many times that, and I don't hate the language. But man does it have some footguns.

Tools without flaws are not the tools that get used for real work. Sometimes you have to suck it up and learn the quirks in the tools you have.

That's not to discourage work on improving the current situation, just an observation on practicality.

Re: How Does React Tell a Class from a Function?

#27

i've used this in the past: function isClass(fn) { return !Object.getOwnPropertyDescriptor(fn, 'prototype').writable; } it relies on the fact that the prototype object of ES6 classes always non-writable.

I don't think that would work for the standard es5 pattern of using functions as classes?

Re: How Does React Tell a Class from a Function?

#28

i've used this in the past: function isClass(fn) { return !Object.getOwnPropertyDescriptor(fn, 'prototype').writable; } it relies on the fact that the prototype object of ES6 classes always non-writable.

Note that this breaks with Babel and TypeScript, since I guess this is one aspect where neither strictly follows the spec. Both of these examples print false:

https://babeljs.io/repl/build/master/#?babili=false&browsers...

https://www.typescriptlang.org/play/index.html#src=function%...

Re: How Does React Tell a Class from a Function?

#29
post #20
post #17

I have written maybe 200 lines of JavaScript in my life, and this article has strongly reinforced my desire to never have to write a single one more. The next time someone asks me what the problem with JavaScript is, I will send them this article. "Scheme for the browser" what a joke. Some excerpts for those that didn't have the strength to sit through the entire thing without pulling their hair out: > If you called…

You don't write js because you like, is because is a competitive advantage: - Write in one language only for both client and server side. Why is good? You just need js devs, no need to duplicate validation and other logic. I'm making a game right now and has js on the backend. I want to make the game single player, now I can just import a file from the client side and > now is single player. If your backend is in jav…

I really don't get how JS on the client and the server is any real advantage - besides sharing some syntax, the models and paradigms are so drastically different it might as well be two different languages. Why make the server so bad when you don't have to? I think JS has its place despite it's flaws, but for the sake of sanity I can't imagine ever using it on the backend by choice. If you want the ease of express, use Flask.

If you can't write your backend in something else and use the same devs, you have bad devs. It's not that hard to pick up a language if you understand the concepts needed to write a client and a server.

Re: How Does React Tell a Class from a Function?

#30
post #22

Earlier quoted context omitted.

One of the points of the post was that you almost definitely don't need to worry about this yourself, especially if you're using React.

If you're going to be using any language seriously, you better understand how functions and objects and classes in that language work.

In most cases I'd agree, but essentially JS has gotten to the point that it's only usable if you write an entirely new language on top of it, like React/Vue/Angular have. All of them are basically to avoid the confusion that arises from the weird quirks of JS, like it's classes implementation. These languages then also try to integrate the few positives of JS into their paradigms, and IMO they are decently successful to the point of usability for a frontend.
Post reply on HN