title: Leaflet - how to add a static function to class?
body: <p>I'd like to add a function to <a href="http://leafletjs.com/reference.html#geojson" rel="nofollow">L.GeoJSON</a> called "getLatLngPath", which will take a geojson object and shoot out a single array of latlngs for any LineString or MultiLineString features in the geojson.  Simple.  </p>
  
  <p>Because I'm not overriding any code, and it's a static function, my thought was to use the <a href="http://leafletjs.com/reference.html#class" rel="nofollow">include()</a> method in the hopes I could access the function as L.GeoJSON.getLatLngPath(...).  Code:</p>
  
  <pre><code>L.GeoJSON.include({
      /*
       * Returns a single array containing all the latlngs from each LineString feature
       */
      getLatLngPath: function(geojson, reverse) {
          reverse = typeof reverse === undefined ?  false : reverse;
          var path = [];
          if (geojson.type === 'FeatureCollection') {
              for(var i=0; i &lt; geojson.features.length; i++) {
                  // Recursively call this function on each feature
                  path = path.concat(this.getLatLngPath(geojson.features[i]));  
              }
          } else if (geojson.type === 'Feature' &amp;&amp; (geojson.geometry.type === 'LineString' || geojson.geometry.type === 'MultiLineString')) {
              return L.GeoJSON.coordsToLatLngs( // function existing in L.GeoJSON
                  geojson.geometry.coordinates,
                  geojson.geometry.type === 'LineString' ? 0 : 1, // Need one more level deep if a MultiLineString
                  reverse);       
          }
          return this._pruneDuplicates(path);     
      },
  
      /*
       * Prunes duplicate-adjacent latlngs
       */
      _pruneDuplicates: function (path) {
          var i=1;
          while (i &lt; path.length){
              if (path[i-1][0] == path[i][0] &amp;&amp; path[i-1][1] == path[i][1]) {
                  path.splice(i, 1);
              } else {
                  i++;
              }
          }
          return path;
      }
  });
  </code></pre>
  
  <p>(Note, code is not tested yet, and it's not relevant to this question.)</p>
  
  <p>Calling L.GeoJSON.getLatLngPath(...) doesn't work -- it says it is not a function.  However, it works if I call the factory method (which just returns a "new" instance of it):</p>
  
  <pre><code>L.geoJson().getLatLngPath(...);
  </code></pre>
  
  <p>I don't mean to quibble, but this is ugly.  I shouldn't need to create a new object for a static method  How can I make my function a static method called right from L.GeoJSON?</p>