Facebook App Devs Get Javascript

It has been an oft-lamented fact of the Facebook Platform thus far in its life that, in order to use all but the most simple of Javascript functionality–the cornerstone of the AJAX technology so loved these days–Facebook app developers have had to host their canvas pages in an iframe, thus foregoing the use of Facebook’s convenient FBML. There has been, in other words, a trade-off between functionality and the ease of designing an app that integrates well with a user’s Facebook experience.

It looks like that trade-off will no longer be a problem, as Facebook has just released to all developers the ability to use their (beta-version) “Facebook Javascript”, or FBJS. As you can see for yourself at the FBJS documentation on the developers’ wiki, Facebook has put a lot of engineering time into creating a coherent API that allows devs to use pretty much the full power of Javascript within their applications on Facebook’s own pages, while keeping Facebook itself free from the damaging effects of buggy or malicious third-party Javascript. For those security reasons, using FBJS will take a little getting used to when writing complicated scripts, but the Javascript language itself remains unchanged, including the use of prototypes and objects.

This move gives app devs more power than previously possible, since FBJS can also be run on a user’s profile page itself, whereas before this was not allowed. Still, Facebook requires that a profile viewer first interact in some way (a mouse click, for example) with an application before any of that application’s particular FBJS events can fire. Thus, annoying behavior by apps the viewer doesn’t care about is prevented. I haven’t seen it in print yet, but I also imagine that many browser-wide Javascript actions (such as popping up a browser dialog box) will be disabled.

The facet of FBJS which should bring the most change (or hype) is the opening up of a Facebook-style Javascript DOM and several powerful AJAX functions which allow devs to take their AJAX operations into their own hands. Previously, Facebook only allowed a static “Mock AJAX” functionality which felt slow and cumbersome. They give an example of their FBJS AJAX object in action, and it seems much more promising than its less-evolved older brother.

In their granting devs the ability to use more powerful tools in a language most of them already understand, Facebook continues to edge its way (somewhat slyly, perhaps) towards becoming the premier (or most attentively-followed, anyway) environment for developing socially-aware internet applications.

[tags]facebook,apps,javascript,fbjs,fbml,ajax,developer,facebook-apps[/tags]