After a bit of prodding around I've not only found out that selecting JavaScript objects and arrays with jQuery is fully supported, but there are also some potential use cases! It all started a couple of weeks ago when I thought it would be cool to bind custom events to actual JavaScript objects.
Critical jQuery Info: How to pronounce “live”
After weeks of debate an answer has emerged. Live rhymes with "jive"? Or live rhymes with "give"?... that was the discussion point that was starting to turn ugly... In the live/jive corner: the "live" event is always on - like a live broadcast. In the live/give corner: the corresponding remove event is called "die", so it's "live & die".
After finally getting fed up of saying "...just use the live/live event", @twalve realised that our heros are merely a single tweet away and hit up Brandon Aaron for the answer... and here it is:
Decision making
- Teenage Turtle Mutant Ninjas
- Ninja Mutant Teenage Turtles
- Turtle Mutant Teenage Ninjas
- Teenage Ninja Turtle Mutants
- Turtle Teenage Ninja Mutants
- Ninja Turtle Mutant Teenagers
- Mutant Turtle Ninja Teenagers
- Ninja Teenage Turtle Mutants
- Mutant Teenage Ninja Turtles
- Turtle Mutant Ninja Teenagers
- Mutant Teenage Turtle Ninjas
- Teenage Ninja Mutant Turtles
- Ninja Turtle Teenage Mutants
- Mutant Ninja Teenage Turtles
- Teenage Mutant Turtle Ninjas
- Turtle Ninja Mutant Teenagers
- Teenage Turtle Ninja Mutants
- Mutant Turtle Teenage Ninjas
- Ninja Teenage Mutant Turtles
- Ninja Mutant Turtle Teenagers
- Turtle Teenage Mutant Ninjas
- Mutant Ninja Turtle Teenagers
- Teenage Mutant Ninja Turtles
- Turtle Ninja Teenage Mutants
Closures with self-invoking functions
Just a quick note-to-self... I'm a big fan of using self-invoking anonymous functions to keep stuff out of the global namespace, but I forgot that they are also nifty for keeping variables in scope via closures. Here's the problem... Let's say with have an array that we'd like to populate with functions. The functions simply log their index to the console:
Using jQuery on JavaScript objects (Part 1)
Today I was trying to decouple some JavaScript classes in a game prototype I've been working on. I didn't want to get into implementing some kind of interface behaviour, and so I thought about a simple Observer pattern. There are a bunch of solutions around the tubes (and indeed I'll probably use one of them) but I started wishing I could just use jQuery's custom events directly on my JavaScript classes.
This idea seemed pretty wacky to me, and made me smile: jQuery events attach themselves to DOM elements - wrapping a JavaScript object in the jQuery selector seemed ludicrous - I mean, should I be able to do $(class).hide()?! No, of course not. But none the less, my curiosity got the better of me, and I tried this lil' snippet:
Read on for more »
Esrever ni sdrocer gniyalp
I'm getting pretty sick of people coming up to me on the street and asking how they can play their records backwards to hear the devil. "I can't spin it backwards at a constant rate" they cry, "and I get tired after a while. What can be done?!". It's upsetting that this problem still plagues our society when the solution - past down from drunken uni student to drunken uni student for decades - is easy, and requires fewer household items than an average Curiosity Show experiment.
Soldier Soldier
Game of Life
Conway's Game of Life is a simple cellular automaton based on a few simple rules. There's about fifty gabillion implementations of it around. Here's mine: Game Of Life in Javascript (rendered, of course, on Canvas). I just followed the rules on the Wikipedia entry, so I'm not 100% sure it's fully "Game Of Life Compliant", but it seems right...
Smoking Canvas
On the way to work today I remembered an old trick to create a "fire" effect: you randomly assign a colour to the pixels on the bottom row of the screen (in the same hue) and for each row above it take the average of the 3 pixels immediately below it, and 1 pixel that is two rows below it.