[OpenLayers-Commits] r3618 - sandbox/tschaub/geojson/lib/OpenLayers/Format

commits at openlayers.org commits at openlayers.org
Fri Jul 6 13:09:52 EDT 2007


Author: tschaub
Date: 2007-07-06 13:09:52 -0400 (Fri, 06 Jul 2007)
New Revision: 3618

Modified:
   sandbox/tschaub/geojson/lib/OpenLayers/Format/JSON.js
Log:
going natural with Format.JSON

Modified: sandbox/tschaub/geojson/lib/OpenLayers/Format/JSON.js
===================================================================
--- sandbox/tschaub/geojson/lib/OpenLayers/Format/JSON.js	2007-07-06 17:00:05 UTC (rev 3617)
+++ sandbox/tschaub/geojson/lib/OpenLayers/Format/JSON.js	2007-07-06 17:09:52 UTC (rev 3618)
@@ -3,29 +3,53 @@
  * for the full text of the license. */
 
 /**
+ * Note:
  * This work draws heavily from the public domain JSON serializer/deserializer
- * at http://www.json.org/json.js.
- * Rewritten so that it doesn't modify basic data prototypes.
+ *     at http://www.json.org/json.js. Rewritten so that it doesn't modify
+ *     basic data prototypes.
  */
 
 /**
- * Read and write JSON. 
  * @requires OpenLayers/Format.js
+ *
+ * Class: OpenLayers.Format.JSON
+ * A parser to read/write JSON safely.  Create a new instance with the
+ * <OpenLayers.Format.JSON> constructor.
+ *
+ * Inherits from:
+ *  - <OpenLayers.Format>
  */
 OpenLayers.Format.JSON = OpenLayers.Class.create();
 OpenLayers.Format.JSON.prototype = 
   OpenLayers.Class.inherit( OpenLayers.Format, {
 
     /**
+     * Constructor: OpenLayers.Format.JSON
+     * Create a new parser for JSON
+     *
+     * Parameters:
+     * options - {Object} An optional object whose properties will be set on
+     *     this instance.
+     */
+    initialize: function(options) {
+        OpenLayers.Format.prototype.initialize.apply(this, [options]);
+    },
+
+    /**
+     * APIMethod: read
      * Deserialize a json string.
-     * @param {String} json A JSON string
-     * @param {Function} filter A function which will be called for every key
-     *                          and value at every level of the final result.
-     *                          Each value will be replaced by the result of
-     *                          the filter function. This can be used to reform
-     *                          generic objects into instances of classes, or to
-     *                          transform date strings into Date objects.
-     * @returns {Object} An object, array, string, or number 
+     *
+     * Parameters:
+     * json - {String} A JSON string
+     * filter - {Function} A function which will be called for every key
+     *     and value at every level of the final result.
+     *     Each value will be replaced by the result of
+     *     the filter function. This can be used to reform
+     *     generic objects into instances of classes, or to
+     *     transform date strings into Date objects.
+     *     
+     * Return:
+     * {Object} An object, array, string, or number 
      */
     read: function(json, filter) {
         // Parsing happens in three stages. In the first stage, we run the text against
@@ -39,7 +63,7 @@
 
                 // In the second stage we use the eval function to compile the text into a
                 // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
-                // in JavaScript: it can begin a block or an object literal. We wrap the text
+                // in JavaScript - it can begin a block or an object literal. We wrap the text
                 // in parens to eliminate the ambiguity.
                 var object = eval('(' + json + ')');
 
@@ -67,10 +91,15 @@
     },
 
     /**
+     * APIMethod: write
      * Serialize an object into a JSON string.
-     * @param {String} value The object, array, string, number, boolean or date
-     *                       to be serialized.
-     * @returns {String} The JSON string representation of the input value
+     *
+     * Parameters:
+     * value - {String} The object, array, string, number, boolean or date
+     *     to be serialized.
+     *
+     * Return:
+     * {String} The JSON string representation of the input value
      */
     write: function(value) {
         var json = null;
@@ -82,14 +111,19 @@
     },
     
     /**
+     * Property: serialize
      * Object with properties corresponding to the serializable data types.
      * Property values are functions that do the actual serializing.
      */
     serialize: {
         /**
+         * Method: serialize.object
          * Transform an object into a JSON string.
-         * @param {Object} object The object to be serialized
-         * @returns {String} A JSON string representing the object
+         *
+         * Parameters:
+         * object - {Object} The object to be serialized
+         * 
+         * Return: {String} A JSON string representing the object
          */
         'object': function(object) {
             // three special objects that we want to treat differently
@@ -126,9 +160,13 @@
         },
         
         /**
+         * Method: serialize.array
          * Transform an array into a JSON string.
-         * @param {Array} array The array to be serialized
-         * @returns {String} A JSON string representing the array
+         *
+         * Parameters:
+         * array - {Array} The array to be serialized
+         * 
+         * Return: {String} A JSON string representing the array
          */
         'array': function(array) {
             var json;
@@ -150,9 +188,13 @@
         },
         
         /**
+         * Method: serialize.string
          * Transform a string into a JSON string.
-         * @param {String} string The string to be serialized
-         * @returns {String} A JSON string representing the string
+         *
+         * Parameters
+         * string - {String} The string to be serialized
+         * 
+         * Return: {String} A JSON string representing the string
          */
         'string': function(string) {
             // If the string contains no control characters, no quote characters, and no
@@ -184,27 +226,40 @@
         },
 
         /**
+         * Method: serialize.number
          * Transform a number into a JSON string.
-         * @param {Number} number The number to be serialized
-         * @returns {String} A JSON string representing the number
+         *
+         * Parameters:
+         * number - {Number} The number to be serialized
+         *
+         * Return:
+         * {String} A JSON string representing the number
          */
         'number': function(number) {
             return isFinite(number) ? String(number) : "null";
         },
         
         /**
+         * Method: serialize.boolean
          * Transform a boolean into a JSON string.
-         * @param {Boolean} bool The boolean to be serialized
-         * @returns {String} A JSON string representing the boolean
+         *
+         * Parameters:
+         * bool - {Boolean} The boolean to be serialized
+         * 
+         * Return: {String} A JSON string representing the boolean
          */
         'boolean': function(bool) {
             return String(bool);
         },
         
         /**
+         * Method: serialize.object
          * Transform a date into a JSON string.
-         * @param {Date} date The date to be serialized
-         * @returns {String} A JSON string representing the date
+         *
+         * Parameters:
+         * date - {Date} The date to be serialized
+         * 
+         * Return: {String} A JSON string representing the date
          */
         'date': function(date) {    
             function format(number) {



More information about the Commits mailing list