Wednesday, September 21, 2011

0x0002 Dev Diaries - JS Privates

A little experiment / toy I have, which I might use to keep some decoupling attempts straight.



Using this, I'll be able to allow the various components to maintain properties on other objects they work with, safely, without interfering with one another.


For example, I have a Draggable behavior that can be enabled in a scene and allows objects in the scene to be, obviously, draggable. During this use, the behavior code may often need to set properties on the objects to track dragging state, but needs to do so without interfering with other behaviors setting properties of their own, even other instances of the same behavior. This simple utility enables this.

privates(this, entity).dragPath = [];
privates(this, entity).dragPath.push(curPos);


...


drawPath(privates(this, entity).dragPath);


The concept this is trying to express is that the first object owns a set of private properties attached to the second object, and this works much like private attributes in many languages but works with delegation and composition, rather than inheritance.


My rendering system will be using this to take the general description of a sprite object and attach to it loaded images, animation state, and flags needed to manage redraw orderings, without mucking in the namespace of the object itself.

Sunday, September 18, 2011

New post on my game development progress.
I've been tinkering on a small Javascript and Canvas engine for the last few weeks, and I'm mostly happy with the results, if not as happy with the progress. Still, it has been steady, so I'll focus on being happy for that part. 
I'm starting to split the codebase into two parts: a javascript utility library, very similar to backbone.js, and the game engine on top of it.
Read the full post
I write here about programming, how to program better, things I think are neat and are related to programming. I might write other things at my personal website.

I am happily employed by the excellent Caktus Group, located in beautiful and friendly Carrboro, NC, where I work with Python, Django, and Javascript.

Blog Archive