|
|
|
|
|
by pachydermic
4667 days ago
|
|
I am lucky enough to have a "Safari books" subscription from my employer, so I have been able to look at some books - I know that one's supposed to be seminal, but I haven't gotten around to it yet. Any other recommendations are welcome. Because I've just started messing with javascript, I'm mostly focused on games programming. But more generally, it seems hard to find information about how to write well optimized javascript (especially in terms of memory usage). This could be my problem, though. I get confused by callbacks and knowing when I'm creating objects (especially functions) versus when I'm reusing them. Callbacks are just confusing the hell out of me - specifically inside of something like requestAnimationFrame... how do I prevent new functions from being created every time I use it? I mean, w3schools is awful for anything but a very quick reference, and while the content on MDN seems to be accurate, it's not very exhaustive and doesn't seem to provide much explanation. Whenever I have a problem with matlab or perl I can go to some great websites or just google my problem to find solutions (and often great explanations) quickly. |
|
I initially posted this, but now I'm not sure if this is what you meant:
Don't do this:
do this: Basically avoid writing anonymous functions for callbacks that are going to be callback-ed more than once.Another thing that might help with memory is make sure you don't keep references to things you want garbage-collected.
E.g. if object `A` has a reference to object `B`, `B`'s memory won't be freed even if you never use it again. MDN has a better explanation and example [1]
As for books I'd recommend Effective Javascript by David Herman.
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memo...