Watch this!
So I’m trying to figure out what keeps changing my DOM elements, and I had heard about this statement called “watch” which is common to all ECMA scripting languages.
this.watch('content', function(id, oldval, newval) {
alert(id + ' was changed from ' + oldval + ' to ' + newval);
}
Wow, this will be useful right? Well it took me a few hours, unfortunately, but I finally figured out that I was calling it wrong. You have to return the newval in this method!
this.watch('content', function(id, oldval, newval){
alert(id + ' was changed from ' + oldval + ' to ' + newval);
return newval;
}
… if you don’t, the value you’re watching will never actually be set! It will tell you it’s setting itself to something else, but since the function returns undefined, whatever you’re watching becomes useless!
What I did for Earth Day (at age 5)
When I was 5, my second grade teacher asked us to draw a picture of a tree. I really loved using crayons, so I pretty much used as much crayon as I could for my tree. I had apples all over it, more apples than any tree could possibly have. People were walking all around the tree with big huge smiles on their face, and up above, of course, was the sun. A big ol' happy sun (whoa, starting to sound like Bob Ross).
Single Page Apps with StateManager
One of the problems with Flash and Ajax applications is that when you click the back button you lose the pages "state" and have to start over when the user comes back.
Matthew Tretter devised a solution aptly named after the Flash class that handles state, StateManager, which uses named anchor tags to keep the browsers back history within the current page and handled with a Javascript callback. It is compatible with all browsers and is surprisingly easy to use.
You can see this code in action at www.a123systems.com and it will soon be featured on my latest project (top secret project).
John McCain Plug #1
So I don't normally like to get to heavy with the politics, but John McCain is a candidate that I didn't realize I'd be excited about until he got elected in the primary. Good job primary voters! (I was not one of them)
I found out the other day that the reason John McCain has such lousy teeth is because his Vietnamese torturers ground them all down to the gums.
I don't even care about his policies, to be quite honest, it wouldn't matter what party he belonged to, I think I'd vote for him either way.
I'm calling this plug #1 because I'm sure there's more to come.
Closures vs. Callbacks
I've been doing a lot of Javascript programming lately. In order to keep my code organized I separate things out into classes. This organization is only useful if you can keep the interconnects orderly. On the one hand you can have one massive chunk of code that starts to become real hard to comprehend, especially for those who didn't write it. On the other hand, you can keep everything in a class and use callbacks and closures to keep everything orderly. The problem I have is when to use a closure, and when to use a callback.
Drifting Ashore
I was in a sailboat sailing around in what seemed like the Carribean, and I decided to anchor the boat and get some sleep. Moments later, I woke up to the sound of waves crashing on the shore and panicked because I thought the boat had lost it's anchor. In reality, the sound of waves crashing was more like dogs barking, and I woke up.
It was actually not that bad, but then I hadn't gotten to the part where the boat crashes against some rocks...
Web Vector Graphics with SVG/VML
Most people think you need Adobe Flash in order to do vector graphics properly. Not true.
I've been researching this topic for the last few months in anticipation of a project I'm starting. There is a great way to render vector graphics on the client. Of course it's not easy breezy. SVG (Scalable Vector Graphics) is the standard that Mozilla and most alternative browsers support, while VML (Vector Markup Language) is the standard supported by Internet Explorer...
Flexible Markup
When it comes to markup it can be tricky to get things right the first time. Ideally you could write your markup just once and no matter how many aesthetic overhauls it takes to get the design just right, the markup is always the same.
I’ve written up some pointers on how I try and optimize productivity when designing the markup by eliminating the need to go back and redo markup, which is repeated more often than anything else in my application designs. Every page has an H1, does every page need a div/h1 combo in order to be flexible?