Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Voxera113886yI cannot see how it can take so much time?
Yes JS has a few quirks but its mot that different once you have the basics. -
rant1ng44626y@Voxera
I'm using vue, with components and all that shit
so, sometimes, the scope isn't so obvious
and sometimes, its develishly unobvious
so reading about basic scope in unealistically simple situations from a tutorial is definitively unhelpful and a complete waste of time, so you are forced to console.log everything and recompile, and run, and scratch your head, and repeat that for an hour, doesn't matter how much you learn about the previous experience, you could have doctorate on javascript scope, and it'll still trip you up with some obscure bullshit situation that will again, waste your fucking time -
Voxera113886y@rant1ng well vue is mostly not js any more and require a very different way of thinking.
Same as react with redux or mobx.
All centers on the state.
Once you understand how the state works its easy again but no, you have very little use of plain js, or mostly any other language, knowlege.
Even functional langs are very different. -
hexc11196yI used Vue a lot, it's not really that bad, just throw a break point in where ever your not sure what the scope is, also Vue has browser plugins to debug Vue stuff.
-
rant1ng44626y
-
rant1ng44626ylike...
return Intl.NumberFormat().format(total);
DOESN'T WORK
but,
total = Intl.NumberFormat().format(total);
return total
DOES WORK
no error messages, no nothing, just doesn't work
this is what i'm talking about -
Voxera113886y@rant1ng is total a local variable or global.
In the later case, maybe its working because you change total.
I checked a few examples and vue often seem to use functions that update a variable instead if returning a value ...
But I don’t know enough to say its so, just throwing ideas around. -
rant1ng44626y@Voxera
it works now
just the fact that I had to know that maybe javascript wants to assign the result of that expression, in this particular case
it's the exact same thing, return (expression)
or var = expression
return var
but one works, one doesn't
go figure
that's javascript -
Voxera113886y@rant1ng Never had that problem in js ever and I have used it since 1998 at least.
So for js it should not matter, I think there is something else, either vue related or there is something with the total variable, maybe a watcher? -
Voxera113886y@rant1ng probably.
I know mobx had some similar quirks as it adds getters and setters to all watched variables and if you dereferences things the wrong way (pulling a value directly) it cannot keep track of what is happening.
Maybe vue has something similar.
Its very powerful but if you do not know about it it can create some very strange bugs. -
rant1ng44626y@Voxera that's exactly what happens
thanks for shedding light on the situation
it just makes for some sometimes very frustrating and time consuming coding sessions -
@rant1ng JavaScript will automatically add a semicolon at the end of a line with a return, even if you have something on the line after. So this:
function foo() {
return
'foo';
}
is equal to:
function foo() {
return;
}
That's probably why putting the value in a variable works but returning it directly doesn't. -
rant1ng44626y@shellbug
ok. thanks for clearing that up, really appreciate it
So, then....
Why?
Is there some sort of logic to doing this or...
just I don't know.. curious. -
@rant1ng automatic semicolon insertion. Look it up.
This is why semicolons aren't required in JavaScript.
every fucking time I use Javascript.
(yes, I'm no expert, but I can pick up ANY LANGUAGE and do this task in FIVE FUCKING MINUTES, NOT AN HOUR!!! FUCK!)
"Gee, I think this button should probably list the total recipients of the mailing, looks like I have to get the total of a column in an object, no problem, hell, i'll do it frontside just for the fuck of it'
yeah, seemed like a good idea.. AN HOUR AGO
ARRRGGGH
fucking javascript scope can take a flying leap off of a tall building, and then NOT FALL to the fucking ground because it will fucking tell me that OOPS gravity doesn't exist for javascript!
UNCAUGHT REFERENCE ERROR
right?
FUCK YOU
die from gravity like you deserve motherfucker
devrant
javascript jumps off tall buildling