Set your Setter and Get your Getter

Getters and Setters are a lot of fun to use. Unfortunately not all browsers implement them. According to John Resig’s post JavaScript Getters and Setters only two browsers currently support them (Opera 9.5 has since been release so make it three). Even before I was really into Javascript programming I used PHP’s Magic Methods __set and __get.

It is with much happiness that I think I can finally say, without seeming like a fool, that: “JavaScript Getters and Setters are now prevalent enough to become of actual interest to JavaScript developers.” Wow, I’ve been waiting a long time to be able to say that.

John Resig – JavaScript Getters and Setters

As much as I would love this to be true, I still do not quite think we are there. Rhino adding support was good, because with that John was able to implement window.location in env.js

So now that we have some background on setters and getters in Javascript. Here is my implementation for browsers that do not already support it.

Read moreSet your Setter and Get your Getter

New Cometd client and server demo

On and off for the last couple weeks I have really been pushing myself to learn Java better. I constantly find myself unable to do things I want to with the languages I usually use (PHP specifically). As I am getting better I am coming to like it a lot more. As any reader of my blog (do I actually have ‘readers’?) know, I am really into Cometd, which the most major implementation of is written in Java. So in order to utilize Cometd Java and push my jQuery plugin further along, I figured it was high time I learn Java. I am really glad I am too. Just in time for my new Android phone too :)

Read moreNew Cometd client and server demo

histarray – An Experiment with Getters and Setters

While doing an experiment with Getters and Setters I whipped together a small lib for a versioning array, the histarray. So far tested only in Firefox 3, it utilizes __defineGetter__(someNumber, function(){}) to return an element from an internal array (the history). Its push method will either overwrite the current revision if it is not the last, or push a new revision into the history.

A Setter is also defined, so no matter where in the time line you currently are, that element will be updated.

Read morehistarray – An Experiment with Getters and Setters

Phomet: A PHP Cometd publisher

Created a small class last night that will allow you to connect, and then publish to a comet server. Code available here. Usage is simple.

$oPhomet = new Bayeux(’http://whereis/my/cometd’);

$oPhomet->publish(’/some/channel’, array(’user’ => ‘derper’, ‘message’ => ‘wee’));

The deconstructor takes care of disconnected you from the server, but if you wish, you can use ->diconnect() before.

This was never really meant to do much beyond simple publishing from PHP. The main limitation that prevent this from working in PHP is, once you have a connection left open (which PHP can do), there is not practical way to allow one connection to communicate with another.

The way Java servlets work allows one thread to wake up the rest and alert them to new changes, propagating to each client. PHP does not allow this.

The closest I have come to Comet in PHP was using a web server called Nanoserv, its implemented in 100% PHP and has the ability to fork off clients but still allow them to communicate with one another with 1 second latency. The experiments I did with it showed it could be done, but I did not continue because the Nanoserv project seems dead.