I have a question that is both game-related and useful for other web-based projects (though in the examples I below try to keep it focused on games). To put it simply, what are the best strategies for keeping JavaScript organized?
Let me clarify: in most of the languages I know (C#, Java, PHP, AutoHotkey, even my limited knowledge of C++) we have classes. And while I know not everyone is a big fan of object-oriented programming, I personally find it makes things a heck of a lot easier to understand and maintain. Each class is usually in a separate file, and once created it's easy to use them (i.e. Player.SwingSword(), Wizard.TeleportTo(x,y), etc.). You know which objects are doing what, and you can use the same class in different games. Even the HTML DOM seems to fall into this category (it is the document "object" model, after all).
But JavaScript is totally different. You can do it in an object-oriented way, but those objects come in the form of functions. It also has some great event handlers (even touch event handlers for mobile devices), but those also look like functions. And you can also just create functions independent of any kind of object or event. So with all these functions floating around, things seem to get confusing fast. Regardless of whether I'm using OOP or not, creating a game or not, my scripts always end up with a long list of functions that just keeps growing and growing.There's got to be a better way.
So what do you guys do to help keep your JavaScript in order? And please, don't even go there with things like JQuery, Node.js, Ajax and other libraries/APIs. I have no problem reading up on APIs in class-based languages, but before I can even touch that in JavaScript I've got to get a handle on managing my own code. Before yesterday (when I was assigned a JavaScript project at work) I didn't even like to use JavaScript at all for this same reason. I get that it can do amazing things with the web, and I'd like to learn to use it better, but at this point I'm just not there yet. If I can get this figured out, then I'll be able to move forward into the deeper stuff, but for now I'm just trying to get the hang of ordinary JavaScript.