Live data from Hacker News

A little bit of plain JavaScript can do a lot

jvns.ca

41–50 of 206 posts

Re: A little bit of plain JavaScript can do a lot

#41

I'm an experienced React developer. I wanted to try out writing a plain vanilla JavaScript application - I enjoy plain JavaScript, it feels close to the metal. It wasn't long before I was craving an application framework that allowed me to cleanly organise and structure my application instead of it rapidly becoming a spaghetti. I also craved the ability to write small simple functions for making components. And I wan…

> it feels close to the metal.

Please tell me you're joking?

Re: A little bit of plain JavaScript can do a lot

#42

I'm an experienced React developer. I wanted to try out writing a plain vanilla JavaScript application - I enjoy plain JavaScript, it feels close to the metal. It wasn't long before I was craving an application framework that allowed me to cleanly organise and structure my application instead of it rapidly becoming a spaghetti. I also craved the ability to write small simple functions for making components. And I wan…

> it feels close to the metal. Please tell me you're joking?

Cmon. Close the the "browser metal".

I of course don't mean close to the CPU that would be silly.

Re: A little bit of plain JavaScript can do a lot

#43

Earlier quoted context omitted.

You described an SPA. Fetch relevant data and render to controls. Not sure why we need canvas for that.

You are correct. I just inadvertently re-invented React.

React is a view engine and isn't using the canvas.

React pretty much is just a fast way to determine what to re-render on a page as a result of a state change.

Re: A little bit of plain JavaScript can do a lot

#44
Nice work! The only advice I’d give is don’t use patterns like

    div.parentElement.parentElement.foo()
It’s inflexible and will break if you ever make dom changes. Use the .closest() selector instead. It’s like a reverse .querySelector (.closest selects ancestors, .querySelector selects descendents) which means you’ll have more specific code.

Re: A little bit of plain JavaScript can do a lot

#45
post #25

If little can do a lot just imagine what I can do with few megabytes: Google Gmail/Youtube engineers

Probably a good batch of spaghetti code if you think vanilla can be used for anything serious. Or rewrite react yourself as another commenter already did.

It is an old meme, that every js-developer, who does not use an existing framework, ends up with his own framework. (also happened to me)

Depending on the scope of the work, this is not allways a bad thing. I like my own framework. It does exactly what I want and I can tweak it to my needs anytime.

But I work alone and don't have to share my code with different developers, otherwise there would be problems ...

Re: A little bit of plain JavaScript can do a lot

#46

I'm an experienced React developer. I wanted to try out writing a plain vanilla JavaScript application - I enjoy plain JavaScript, it feels close to the metal. It wasn't long before I was craving an application framework that allowed me to cleanly organise and structure my application instead of it rapidly becoming a spaghetti. I also craved the ability to write small simple functions for making components. And I wan…

> it feels close to the metal. Please tell me you're joking?

I mean he is a React developer after all, less than 3 levels of abstraction is greased lightning.

Re: A little bit of plain JavaScript can do a lot

#47
post #46

Earlier quoted context omitted.

> it feels close to the metal. Please tell me you're joking?

I mean he is a React developer after all, less than 3 levels of abstraction is greased lightning.

As a React developer I have the strictest policy to never go lower level than the browser and I never touch other fields of computing. I started my computing career in 1986 knowing only React and I'll get to the end of it knowing nothing else.

Re: A little bit of plain JavaScript can do a lot

#49
post #34

Earlier quoted context omitted.

Would you mind explaining what this does?

Its just a helper function to create an element, assign it some properties, and append children elements. Not very much unlike React in the API (emphasis on "interface") but of course the inner workings is as minimal as possible.

Could you explain how it does this?

Re: A little bit of plain JavaScript can do a lot

#50

I agree about the nuisance of creating DOM elements. innerHTML is OK if you’re doing static content, but for anything that needs to be dynamic (untrusted input, event handlers, etc.) I have a little tiny helper library that I carry around in my head and write into projects that need it: const $T = text => document.createTextNode(text) function $E(tag, props, kids) { const elem = document.createElement(tag) for (const…

I also have custom DOM helpers I carry around with me:

* getNodesByType - allows me to get things like attributes, text, and comments directly

* getAncestor - allows me to get a specified element somewhere between a target element and the document.documentElement

Post reply on HN