Tuesday, September 18, 2007

Facebook JavaScript

Just yesterday I was reading Marc Andreesen's latest musings on "platforms." He characterized Facebook's F8 platform as a plugin platform, where everything runs on your server but is shown inside the context of a page on Facebook. Technically he's wrong. If your application uses the Facebook Markup Language (FBML) then a Facebook server interprets the response from your server before sending a final response to the end user. After all, no browser supports FBML (yet?) so something has to turn it into HTML and JavaScript.

Of course a lot of applications don't use FBML at all, and use the IFrame approach instead. I am currently working on just such an application. My reason was not using FBML was simple: I needed JavaScript. I didn't even need complicated JavaScript. I just needed to let users click on an image, then set some hidden fields and submit a form. Pretty simple really, but not possible with FBML. Until today.

I go on Facebook this morning and what do I see? An announcement about Facebook JavaScript. I had actually seen this mentioned as being in beta a couple of weeks ago, and I guess it went from beta to production very rapidly.

Looking at its documentation, the were two puzzling things. First, you have to put your JS, err I mean FBJS, inside XML comments... That's a minor thing, and I can easily imagine how it simplifies their parsing of the response from your server. Next, they've wrapped almost all the DOM properties and methods. This makes sense, after all they don't want people to actually get the real DOM object and start screwing around with Facebook's real estate. But their wrapper uses getter/setters for all the properties ... That just seems arbitrary. If Facebook was written using Rails I would expect something like that, but I don't expect something like this from PHP guys.

There were also some very expected things. Like no JS runs on the profile unless it is triggered by what Facebook is calling an "active" event (like clicking on an image or link.) You can't subclass Array or Function. Does this prevent you from accessing their prototype and overriding default behavior?

Anyways, I am happy to see FBJS. I wish it would have been out sooner, as I think it could have simplified some work I've done in the past.

1 comment:

Anonymous said...

Not being a programmer/developer how hard is it to turn a line of javascript (calling my Aweber form) into FBJS? I'm embedding raw html to get around FB's non-support for Javascript but that entails recopying the html whenever I make a change to the form.