[OpenLayers-Dev] constructor signatures

Gregers Gram Rygg gregersrygg at gmail.com
Fri Jun 18 07:58:48 EDT 2010


How about max 3 arguments for any constructor or method in 3.0? Need
more arguments, use an options object.

The only downside I see with options objects are that it gets more
difficult to read the source code to see what the available options
are. One approach to solve this would be to use fake option classes
for Natural Docs.
  * options - {GridLayerOptions} Hashtable of extra options to tag
onto the layer

Then document the GridLayerOptions in the same file (bottom?):
/**
  * Class: GridLayerOptions
  * Inherits: <LayerOptions>
  *
  * Properties:
  * name - {String} *required*
  * url - {String} *required*
  * params - {Object} *required*
  * .....
  */

It will be difficult to keep the arguments up to date for the class
you inherit from, but maybe it is enough to just document the options
specific for this class, and link to the inherited options "class"
somehow. I'm not very familiar with NaturalDocs, so I don't know if
"Class" is the best keyword for the options object, but I like it
better than some of the docs today (see RootContainer's constructor).
This is similar to what Google Maps does in their documentation:
http://code.google.com/apis/maps/documentation/javascript/reference.html#MapTypeControlOptions

Options objects can have required properties. Just throw an Error if
it's missing. Maybe a required options array on the prototype, so it
can be done in a generic manner.

Errors thrown from a minified script is quite useless, since it
doesn't say anything about class name or line number in original
source. Maybe it's time to integrate a simple logging framework? Can
start a separate thread to discuss this.


Best regards,
Gregers



More information about the Dev mailing list