¿El envoltorio ES5() en el JS SDK de Facebook es de código abierto?

Facebook's JS SDK has recently started using newer ES5 Javascript methods such as Object.keys() y [].map(). They still support older browsers by having an ES5() function that accepts the original object, the name of the desired method, and any parameters. It then runs either the native method or an equivalent JS method if the native one isn't available. For example:

ES5(g.api.whitelist, 'forEach', true, function(ca) {
    s[ca] = 1;
});

or for top-level objects,

ES5('JSON', 'parse', false, r.responseText);

I suspect that this is the result of a preprocessor, and FB's devs are actually writing something more along the lines of

g.api.whitelist.forEach(function(ca) {
    s[ca] = 1;
});

y

JSON.parse(r.responseText);

(presumably with longer variable names too)

Now, assuming I'm right that there is a preprocessor, is the ES5() function and associated preprocessed are an open-source project or something in-house? If it's in-house, can anyone from FB comment on the possibility of open-sourcing it? It's something that I could find tremendously useful.

preguntado el 30 de junio de 12 a las 21:06

ES5 function? Why not just manually implement the new ES5 API for IE8 (or just include ES5-shim), y luego use Object.keys() y [].map() ¿normalmente? -

I am basically implementing it manually right now. That's lead to bugs where someone forgot to use the "special" version and just went with the native one. ES5-shim modifies the native objects and there's an off-chance that it will break other scripts. (I'm making widgets that are meant to go into other people's web pages. Not breaking their existing scripts is a high priority.) -

Can you bundle third-party libraries with your widget? -

So, you'd like to use the ES5 API in your source code, and then have that source code compiled into ES3... Caja does that. Check it out. "Caja emulates all the new features of ECMAScript 5, including getters and setters, non-enumerable properties, and read-only properties. New browsers support these features natively, but older browsers still have a significant user base. Caja emulates these new features on browsers that don't support them natively."-

Similar to Caja, see also Mascara (commercial) y Traceur (open source)... -

3 Respuestas

We are indeed using a preprocessor (based on jspatch) which lets us write regular ES5 code. The ES5 function itself is basically a wrapper around polyfills from DND y JSON3.

Not only does this let us write ES5, but it avoids us using faulty implementations of things like Function#bind and JSON.stringify.

La publicación del blog is now out.

Respondido el 11 de junio de 19 a las 18:06

Hey, thanks! I'd love to see that blog post - please leave a link here when it goes up :) - nathan frito

No problem, and thanks for submitting bug reports that we can actually execute on :) - Sean Kinsey

Hah, I do my best. Everybody hates vague bug reports. - nathan frito

Oh, I didn't realize at first that you are the guy behind easyXDM - thanks for that too! I'm going to be in SF in a couple of weeks and then again around Halloween - we should get together for coffee some time - email me if you're up for it: firstName.lastName@gmail.com - nathan frito

Searching Facebook's open-source github repositories does not show any ES5 methods. I explicitly checked out and recursively grepped the ones that mention javascript. So it does not appear that what you are seeing is publicly available from them. I could not find it anywhere else either.

If you need ES5 backwards compatibility, have a look at this es5-calce

Respondido 30 Jul 12, 22:07

Someone else mentioned es5-shim in the comments, but that won't work for me because my script is getting embedded in other sites and es5-shim modifies native object prototypes. - nathan frito

http://connect.facebook.net/en_US/all.js

is this what you want? it doesnt list any licenses in the file and it seems to be autogenerated?

https://github.com/facebook/connect-js/

?

this would point to "yes" and the license would be apache?

Respondido 31 Jul 12, 00:07

I want the original source used to generate the first link. The github link hasn't been updated in over a year. - nathan frito

well it seems to me that atleast the predecessor of that code is in github and is apache-licensed, so i would just ask facebook. - Markus Mikkolainen

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.