Object-Oriented Javascript
submitted 1 year ago * by fschmidt from (self.programming)
view the rest of the comments →
[–]BanditMcFuklebuck 1 insightful - 3 fun1 insightful - 2 fun2 insightful - 2 fun2 insightful - 3 fun - 1 year ago (3 children)
Wow, you can overload a function junst by putting ||??? so if there's a value for init it initializes it but if there's not it junst uses 0! I don't think Java or C++ can do that can they??
[–]IMissPorn 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 1 fun3 insightful - 2 fun - 1 year ago (2 children)
It's an interesting quirk. In JS "A || B" technically means "If A is true, then A, otherwise B". This does make it function like you'd expect a logical OR to do, but it has more arcane uses as seen here. I'm kind of conflicted on stuff like this, it's fun to learn and can be handy, but it doesn't make for the most readable code. I'm kind of surprised OP finds it acceptable considering how much he hates other weird shortcuts.
[–]fschmidt[S] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 0 fun2 insightful - 1 fun - 1 year ago (1 child)
This idiom is readable. If you read "||" as "or" then "x = y || z" makes sense. This is in contrast to arrow functions and default parameter values that you see x0x7's code which just don't make sense unless you know what they are.
[–]IMissPorn 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 0 fun2 insightful - 1 fun - 1 year ago (0 children)
I see. I suppose that makes sense.
use the following search parameters to narrow your results:
e.g. sub:pics site:imgur.com dog
sub:pics site:imgur.com dog
advanced search: by author, sub...
~4 users here now
Links:
view the rest of the comments →
[–]BanditMcFuklebuck 1 insightful - 3 fun1 insightful - 2 fun2 insightful - 2 fun2 insightful - 3 fun - (3 children)
[–]IMissPorn 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 1 fun3 insightful - 2 fun - (2 children)
[–]fschmidt[S] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 0 fun2 insightful - 1 fun - (1 child)
[–]IMissPorn 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 0 fun2 insightful - 1 fun - (0 children)