I’ve spent the past couple weeks tooling around in my spare time with OO JavaScript, jQuery and jQuery UI. It’s been monsterous fun, and the result is a simple JavaScript chess game, which uses a bit of all three.
As the title implies, this lead me to remember a few simple truths when working with JavaScript and frameworks like jQuery.
1. The DOM is Limited
The DOM is a tool well suited to displaying magazine articles and the standard text content that we’re used to seeing on the web. It’s not particularly well suited to multimedia or games interaction. The chess game I’ve created isn’t particularly complex, but even here I felt limited by the way the DOM was designed. That’s not to say the DOM can’t do more, it’s been proven it can, but it wasn’t designed for it.
2. It’s all JavaScript
You read a lot of funny questions on the web about “how do I do x in jQuery?”. jQuery isn’t fundamentally different than JavaScript – it’s a JavaScript library built to make manipulating the DOM easier. Don’t treat it like another language; the core of your code will still revolve around writing solid, maintainable JavaScript. There are hundreds of fantastic resources on the web about javascript. Use them.
3. JavaScript has some Awesome Tools.
Chess feels like a game of exceptions. This piece can move here except.
The result is a tree of if/else statements governing when a move is legal and when it’s not. While I didn’t figure out how to clean this all up completely, this article by Angus Croll showed me a couple of great tools to save my sanity.
Hi AndrewThanks for making your Javascript chess game available.I want to write javascript chessgame for me webpage chessboard but not sure how to!Hopefully I can find some hints in your game-thanks