Facebook's Unique Ajax Support

The Facebook Platform is quietly moving beyond its initial, somewhat limited "mock ajax" roots for platform UI development. They've quietly released a beta version of FBJS, Facebook JavaScript. FBJS is an interesting twist on how to allow richer intereactivity without requiring developers to resort to using iframes (which are inherently more isolated from the full Facebook User Experience). Some useful notes from their wiki:

FBJS is Facebook's solution for developers who want to use Javascript in their Facebook applications.

Most providers who allow developers to embed Javascript within their domain force developers to use iframes to Sandbox their code. Facebook has taken a different approach to this problem. Javascript that you give us will be parsed, and any identifiers ( Function and variable names) will be prepended with your application id. For example, the following code block:

function foo(bar) {
  var obj = {property: bar};
  return obj.property;

will become:

function a12345_foo(a12345_bar) {
  var a12345_obj = {property: a12345_bar};
  return a12345_obj.property;

This creates a virtual scope for every application that runs within Facebook's page. From there we expose certain functionality through a collection of Javascript objects which allow you to modify your content on Facebook. Our objects are made to mimic the functionality of Javascript as closely as possible, but it may take some getting used to for people who are already adept with Javascript.

The Javascript syntax you've come to know and love (or hate) is exactly the same. You can create objects, use anonymous functions, create timeouts and almost any other thing you can think of...

FBJS supplies a very powerful AJAX object for developers. It supports retrieving JSON, FBML, or raw text from remote servers. To use it, just instantiate a new Ajax class.

The pace of innovation at Facebook continues to raise the ante for all competing social network platforms who have yet to release even their first APIs. [via]

Be sure to read the next Social article: MySpace To Open-up Platform