r/shittyprogramming • • Apr 12 '16

Easy JavaScript game loop

Post image
277 Upvotes

37 comments sorted by

View all comments

28

u/auxiliary-character Apr 12 '16

I forget, does javascript have tail call recursion?

27

u/MC_Labs15 Apr 12 '16

This particular code will throw an error

0

u/[deleted] Apr 12 '16

[deleted]

8

u/MC_Labs15 Apr 12 '16

o_O

5

u/Ilostmyredditlogin Apr 12 '16

Chasing bounties?

1

u/lichorat Apr 13 '16

What bounties?

1

u/Ilostmyredditlogin Apr 13 '16

1

u/lichorat Apr 13 '16

Oh I tried to do that. Turns out Chrome Stalls aren't security related.

1

u/Ilostmyredditlogin Apr 13 '16

Oh -- from what the first guy said, I thought it crashed the tab (which could indicate a bug to exploit).

1

u/lichorat Apr 13 '16

Ah I see. Nah, it just hangs and then you can close the tab, but not interact with it.

9

u/auxiliary-character Apr 12 '16

Yeah, even if javascript has tail call recursion, they're not using return statements at the end.

3

u/Niriel Apr 12 '16

Does JavaScript have a Bottom type? That's the only return type that makes sense for an infinite loop, since it's uninhabited.

4

u/Darksonn Apr 12 '16

No, but they don't have return types either, so it's fine.

4

u/Niriel Apr 12 '16

They don't have a return value, but they do have a return type. Bottom is a type with no value. https://en.m.wikipedia.org/wiki/Bottom_type

6

u/whatIsThisBullCrap Apr 12 '16

Javascript is dynamically and weakly typed. It doesn't matter what the type is

1

u/Darksonn Apr 13 '16

You misunderstand. I know perfectly well what a bottom type is, and I wasn't referring to functions that never return.

I was referring to functions in javascript. In javascript no function has a return type; if they return, they just return a thing. That's why there's no need for a bottom type in javascript.

1

u/ConcernedInScythe May 09 '16

There's an implicit return at the end of the function block, which any decent optimiser should understand.

1

u/serg06 Apr 12 '16

JS throws errors?

13

u/[deleted] Apr 12 '16

ES6 does, but I don't think any browsers support it yet.