5
theuser
7y

I wish they would shorten the element reference method calls in js, it's just a tedious ordeal typing document.getElementByID() or getElementsByClassName() all the damn time.

Comments
  • 5
    @theuser it's better to have longer variables and method names, than not knowing exactly and isntantly what they do. Debugging is an absolute hell when you have complex code that isn't explicit in their naming.
  • 2
    I agree with both of these statements
  • 1
    you can do it yourself:

    document.f = document.getElementByID;
    document.f(...);

    Im not saying that this is a good idea, but it can be done.
  • 1
    @JohanO Good to know, but I think I would rather have my IDE autocomplete for me (using WebStorm)
  • 7
    This is where jQuery comes in handy.
  • 0
    Why not document.querySelector()?
  • 1
    I quess you could wrap querySelector to $, so you don't have to use jQuery. Because of... it's too mainstream? There really not excuse not to use jQuery but I like to run as little libraries as possible on my sideprojects. Because why not.
  • 0
    Why would you even need to touch the DOM manually?

    My projects have exactly one place where I touch DOM:

    React.render(
    <App />,
    document.getElementById('app-root')
    )

    If you need more then you're doing it wrong
  • 0
    @Froot Mostly because I'm learning plain JS.
  • 0
    @theuser Ah then it makes sense. And it's the right path too, defenately know how HAS works before going into React 😊
  • 1
    @Froot Aha, a history lesson! :D
  • 1
    Get yourself a good editor? I agree with you but changing it would basically break the whole web. When I type "d.geti" it corrects it to getElById and so on
  • 0
    @Froot Using a patented "open-source" project is "doing it wrong" imo.
  • 0
    @Walz I've had this discussion here many times, I'm not going to have it again. You might think that everything should be open-source, I don't. I'm not going to use some inferior second class product just because it's open-source.

    Also, go read up on economics a bit, parents are not all that bad
  • 1
    @Froot I don't want every things I use to be open-source.
    React is in a weird middle ground, it's open-source until Facebook takes the license back from you.
    And, more importantly, it's said almost nowhere (Let's not pretend people read the LICENSE file).
    In the end, its depends on how much you trust Facebook.
    You can't say that React is the only way to go when there are tons of others framework that could better fit one's need.
    "If you only have a hammer everything is a nail" or something like it, you get the idea.
  • 0
    @Walz Well React works and it's good at what it does. It also has a great ecosystem around it. Why would I use anything else?
  • 1
    @Froot The same thing can be said of Angular, but neither are lightweight and sometime that what you need.
    Or you're building a proprietary app and would prefer to not get involved with the React licence.
    You should assess your project need and then choose the right framework and not force your favorite in every project.

    Also, and I know it's crazy, but you may not even need JS. (Or just a little and vanilla is enough)
  • 0
    @Froot react is really unnecessary when building, let's say a sidebar with just a few elements. Something like vue would be a much better fit.
  • 0
    @Dacexi Well of course react is overkill if you just want JS on some buttons.

    I'm talking about SPAs here.
Add Comment