Facebook Cookbook - Jay Goldman [101]
The call to set the onconfirm handler for the doIt Dialog was automatically changed from changeIt to a12345_changeIt to match the new function name.
Finally, even though the div itself has been renamed app12345_it, the call to a12345_document.getElementById still refers to it as plain old it. Since this is no longer a call to document.getElementById but has instead been contextualized to your app’s sandbox, you’re now making a call to a prototype function defined in fbml.js (look for fbjs_main.prototype.getElementById near line 72). The new version of the old standby basically translates between the Sandbox and the DOM, prepending your app’s ID to a standard getElementById call and then passing the resulting object back to you. There are a number of standard JavaScript objects that get similarly remapped, so don’t worry if you see things like Math getting renamed to a12345_Math. Here’s the full list:
Ajax (Facebook-specific)
console
Date
Dialog (Facebook-specific)
document
escape
Facebook (Facebook specific)
Math
RegExp
setInterval
setTimeout
String
undefined
unescape
The end result should be that you don’t even need to think about this, but sometimes bad things happen to good code. As we’ll see in Avoiding Heartache When the DOM Changes later in this chapter, very complicated and fragile code constructions might break given the translation into FBJS, particularly if Facebook makes any changes to the way Platform interprets code. If you remember the primary rule of all programming—Keep It Simple, Stupid (KISS)—you should be fine.
Losing Your < >s
Problem
The angle brackets (< and >) keep disappearing from my rendered FBJS code.
Solution
Facebook suggests wrapping code within
This will likely change at some point as the FBJS parser matures, so you may not find it necessary, but YMMV (Your Mileage May Vary).
Discussion
This was standard practice for a long time to support older browsers that didn’t handle
-->