JavaScript in the Facebook context is different inasmuch as it all will get rewritten as it goes through Facebook. To get a sense of the differences (of which there are many), start with the FBJS Documentation. Creating your first application is a good primer.
The site that will become your bible is wiki.developers.facebook.com, it is canonical in terms of the FB platform. Additionally, as we all have come to know and (love? hate?) the Facebook platform is a moving target, so it's useful to keep up with things via the Developers Group on Facebook. I also like the blog Inside Facebook.
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 gets
parsed, and any identifiers (function
and variable names) get prepended with
your application ID. For example, the
following code block:
function foo(bar) { var obj = {property: bar}; return obj.property;
}
becomes:
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.
From there we expose certain
functionality through a collection of
JavaScript objects that 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.
Many items which are simply elements in plain JavaScript must be accomplished with special method calls in FBJS. For example when referring to a form field's value in JS you use .value
, whereas in FBJS you need to do .getValue()
. It's these differences that prevent simply cutting and pasting JS from elsewhere into Facebook.
That's a basic primer. That should get you started. Best to you!