←back to thread

517 points bkolobara | 1 comments | | HN request time: 0s | source
Show context
merdaverse ◴[] No.45043051[source]
Code written below your line gets executed if you don't return early. More breaking news at 8.

Seriously, why would you think that assigning a value would stop your script from executing? Maybe the Typescript example is missing some context, but it seems like such a weird case to present as a "data race".

replies(8): >>45043245 #>>45043339 #>>45043398 #>>45043537 #>>45043876 #>>45046033 #>>45046975 #>>45049155 #
Arch-TK ◴[] No.45043398[source]
Assigning to `window.location.href` has a side effects. The side effect is that your browser will navigate to wherever you assigned, as if you had clicked a link. This is already a surprising behaviour, but given that this assignment is effectively loading a new page in-place, kind of like how `execve` does for a process, I can totally see how someone would think that JS execution would stop immediately after a link is clicked.

It's obviously not a good idea to rely on such assumptions when programming, and when you find yourself having such a hunch, you should generally stop and verify what the specification actually says. But in this case, the behaviour is weird, and all bets are off. I am not at all surprised that someone would fall for this.

replies(4): >>45043684 #>>45043902 #>>45044345 #>>45048334 #
1. dkarl ◴[] No.45044345[source]
> when you find yourself having such a hunch, you should generally stop and verify what the specification actually says

It greatly heartens me that we've made it to the point where someone writing Javascript for the browser is recommended to consult a spec instead of a matrix of browsers and browser versions.

However, that said, why would a person embark on research instead of making a simple change to the code so that it relies on fewer assumptions, and so that it's readable and understandable by other programmers on their team who don't know the spec by heart?