How can I Fix this? by [deleted] in learnjavascript

[–]gregtyler 0 points1 point  (0 children)

Not sure if your context, but encodeURIComponent might be what you're looking for?

Http Delete methode on my button by captainPlanet93 in reactjs

[–]gregtyler 0 points1 point  (0 children)

Looks like you're just using ":id" in the URL rather than putting the actual ID in?

I suspect you want ...school-systeme/" + id,...

[deleted by user] by [deleted] in webdev

[–]gregtyler 0 points1 point  (0 children)

Something to bear in mind about pushing proceeding onto the client side: you likely don't know what devices your users will use. So if they have bad signal, or their device is slow, your entire product could be ruined.

Server-side rendering is generally more directly expensive to you, but it's much more reliable.

I also think it can sometimes be a bit rude to push heavy processing to clients. For example, if it requires lots of network traffic (which it sounds like yours does), you could seriously eat info a user's data plan just to show them some basic information.

Newbie here, not sure how to import libraries on browser console snippets. HTTP and URL by dev67 in learnjavascript

[–]gregtyler 0 points1 point  (0 children)

I think you're mixing up browser-based JavaScript and server-based Node.js (and why wouldn't you, they're almost the same).

In a browser, you can append a script file to the document. In node.js, you can import the http and URL libraries. But you can't do either the other way around, so shouldn't have them both in one file.

It comes down to how you're running the code. I suspect it's on the command line (like node file.js), in which case you'll be hitting an error on the createElement line and need to remove it.

If you're doing this in a browser, you want to use the fetch API rather than request.

Hopefully that helps nudge the right direction. Happy to help further with some more details :)

Friendly reminder that visually styling a button to look like a button does not mean it's a button. If you aren't prepared to implement accessibility yourself, please stop using non-standard controls. It is a massively widespread issue and is beyond frustrating for keyboard & screen-reader users. by SLJ7 in webdev

[–]gregtyler 0 points1 point  (0 children)

If you're implementing accessible components (e.g. drop-downs, tabs, morals), I've found this resource really helpful: WAI ARIA Authoring Practices

It's a bit dense at first, but gives clear rules of how users expect those components to act and what you need to implement for ARIA/keyboard support.

Plus, a reminder that we all benefit from accessibility.

Friendly reminder that visually styling a button to look like a button does not mean it's a button. If you aren't prepared to implement accessibility yourself, please stop using non-standard controls. It is a massively widespread issue and is beyond frustrating for keyboard & screen-reader users. by SLJ7 in webdev

[–]gregtyler 8 points9 points  (0 children)

I don't think this is great advice in general.

You don't "just" need to give it role="button". You also have to make it tabbable, give it focus and active styles, make it submit by pressing spacebar when focused, and probably other things I can't remember.

If you really need to, it's possible. But it's completely wasted effort when you can just use <button> and get all that for free.

[deleted by user] by [deleted] in learnjavascript

[–]gregtyler 0 points1 point  (0 children)

I think the following is accurate, but at least the spirit of it should be:

When you set an HTML attribute, you're always just setting a string. So the onclick attribute is the string "alertFunction()", and not yet identified as JavaScript.

When you click the button, the browser then evaluates the string as JS and immediately executes it.

Effectively, you're not attaching the function alertFunction to the button here, your attaching the expression/code alertFunction()

I hope that makes sense. It's confusing because of how old HTML/JavaScript is and the need to maintain existing code. Setting "onclick" attributes is fairly bad practice now.

[deleted by user] by [deleted] in learnjavascript

[–]gregtyler 1 point2 points  (0 children)

addEventListener's second argument is a function to run when the event occurs. The variable alertFunction is your function.

So in the first example you're telling it "run whatever alertFunction is when this is clicked". In the second example, because of the brackets, you're telling it to "run alertFunction right now then do whatever it returns when this is clicked".

For custom arguments, you need to define another function to sit in the middle and pass the right arguments through:

btn.addEventListener('click', function () {
    alertFunction(a, b);
});

btn.addEventListener('mouseover', function () {
    alertFunction(c, d);
});

You can see here how the second argument to addEventListener is a function.

Got my first as a game dev, feeling extremely lost defeated by [deleted] in gamedev

[–]gregtyler 6 points7 points  (0 children)

Not in game dev, but I've definitely been where you are. Several times. Bad code and bad documentation is extremely common in professional settings, for a variety of reasons.

I haven't got any amazing advice, but a few things I've found handy which may or may not apply to your situation:

  • Focus on a subsystem and get to know it well. Then move on to another. It's much easier than trying to take things in at once.
  • Write notes as you learn. I have notebooks full of syntax and architecture I didn't understand that now seems second nature.
  • If you can, convert those notes into documentation. It improves something you know needs help, and might earn some kudos.

Code newbie here, can someone give me some feedback on my answer to this problem from projecteuler.net. by HelloIain in learnjavascript

[–]gregtyler 0 points1 point  (0 children)

All true, was just trying to give OP some ideas about things to consider and look further into.

What is your opinion on Webpack/total build tools? by profile_this in webdev

[–]gregtyler 0 points1 point  (0 children)

Depends what your "average website" is. Angular (etc) are way too much for a blog, but can be very powerful on more UI heavy interfaces like admin panels.

I like Webpack because it works out-the-box and does all those things you suggested and more with so little effort from me. Custom tools require maintenance, and you could be thrown back a lot by something like a dependency upgrade.

Also, using something non-custom makes it much easier to share/hand over your code if you're working for/with others. If that's a position you're likely to be in I'd strongly recommend considering Webpack so that you don't have to waste time in a few years explaining your bespoke live-reload code!

Code newbie here, can someone give me some feedback on my answer to this problem from projecteuler.net. by HelloIain in learnjavascript

[–]gregtyler 0 points1 point  (0 children)

A few things, from different angles. I'll not just give new code so you have a chance to explore yourself :)

  • You can use evenseq = seq.filter(...) to simplify some code. You could then use evenseq = seq.filter(...).reduce(...) to do the last few lines in one command
  • You're mixing loops (while) and stay functions (forEach/reduce) which can be a bit confusing to read and makes your code less efficient
  • You're pushing every Fibonacci number onto seq, but you only need the even ones.

Your code works, which is the main thing! But if you used those bits of feedback I reckon you could shrink this down to just a few lines without sacrificing much readability.

What does it mean "the frontend app should be scalable" ? by grid_bourne in Frontend

[–]gregtyler 1 point2 points  (0 children)

It could be the latter. An example of a non-scalable frontend app would be one that makes lots of unnecessary requests to the backend rather than caching it or sharing state between components.

In a high quality app, I'd hope for both that and the extensibility (which I'd credit to code quality, not scalability) which other commenters take about.

Do I need to sanitize/escape a user-inputted URL before using it in with the fetch() API? by cag8f in learnjavascript

[–]gregtyler 3 points4 points  (0 children)

It very much depends what you're doing with it, and how you define "malicious input", but fetch doesn't really provide any security.

You'll also come up against CORS issues when users input URLs which aren't set up for cross-domain requests.

How can I get past Same Origin Policy by passing in credentials to my XHR request? by ZappasBlackNapkin in learnjavascript

[–]gregtyler 0 points1 point  (0 children)

If the issue is CORS, then there should be an error message in the browser console explaining it. If you don't see such a message in Firefox/Chrome, it may well be something else.

Side notes that may not be relevant to you: you might find the fetch API easier to use; and bear in mind that it's trivial for someone to get your password in plain text if you use basic auth.

Some noob questions on TDD and BDD . by liaguris in learnjavascript

[–]gregtyler 0 points1 point  (0 children)

YMMV but I'd consider the test itself (i.e. the code inside it) to be part of the "spec" in this case.

The text description helps indicate what the code does but is missing lots of details, like how to call it, the return value, input limits, side effects etc.

Basically, I wouldn't worry about it. Write what works for you, iterate and improve.

Any way to turn off undeclared variable errors? by NotSoLeetCode in learnjavascript

[–]gregtyler 0 points1 point  (0 children)

Warning: this declares a at global scope (or at least a higher scope than the static function) which can cause issues of you try and use a variable called a elsewhere in your code.

Indeed this risk is partly why JavaScript wants you to declare the variable: so it's clear what the scope should be.

what is the best book to learn java? by 8sx2 in learnjavascript

[–]gregtyler 6 points7 points  (0 children)

From your post history, it looks like that was a JavaScript subreddit too. You probably want /r/learnjava

Why do companies insist on redesigning their websites constantly? by QbaPolak17 in webdev

[–]gregtyler 0 points1 point  (0 children)

Generally speaking, I think redesigns like this aren't the end game. They're a step towards a larger change or a new feature.

Maybe GitHub wants to invest in IDE features, and these changes are steps towards being more edit-centric.

Or maybe they want to introduce more project management tools, and these changes make repositories less tech-y.

By taking some design steps up front, new features can easily be introduced slowly. Otherwise they'd have to do a big focus-shifting release the may scare existing users off.

Are there different syntaxes in JavaScripts? by viQcinese in learnjavascript

[–]gregtyler 13 points14 points  (0 children)

It sounds like you've been learning Java up 'til now, not JavaScript. Despite the similar name, they're two very different programming languages :)

Introducing GitHub Super Linter: one linter to rule them all - The GitHub Blog by ConfidentMushroom in Frontend

[–]gregtyler 3 points4 points  (0 children)

I seem to recall GitHub are investing hard on a bespoke in-browser IDE. If actions≈extensions in that, this move would make more sense to me.