Labs/JS Modules: Difference between revisions

document the new JSON module
(document the resetBranch method)
(document the new JSON module)
Line 11: Line 11:


= Modules =
= Modules =
== JSON ==
The [http://hg.mozdev.org/jsmodules/file/tip/JSON.js JSON module] wraps the incompatible Firefox 3.0 and 3.5 JSON APIs, presenting the 3.5 API on both versions, for extensions that support both versions of Firefox.  Import this module to parse and stringify JSON in both 3.0 and 3.5 without checking the application's version each time.
Note: don't import this into the global namespace!  If you do, you'll hork native Firefox 3.0 code that expects the 3.0 API.  Instead, import it into your own object like this:
let MyExtension = {
  JSON: null,
  ...
};
Components.utils.import("chrome://myextension/modules/JSON.js", MyExtension);
// Now MyExtension.JSON is an object implementing the Firefox 3.5 JSON API.
This module also works in Thunderbird 3.0, which uses Firefox 3.5's API.
The Firefox 3.5 JSON API is documented in the article [https://developer.mozilla.org/En/Using_JSON_in_Firefox Using JSON in Firefox].


== Logging ==
== Logging ==
canmove, Confirmed users
2,056

edits