Skip to content

this is bound to functions, need to make that a arrow function #2

Open
@oehm-smith

Description

@oehm-smith

This code fails:

if (Array.isArray(objects)) {
      geojson = { type: "FeatureCollection", features: [] };
      objects.forEach(function(item) {
        geojson.features.push(
          this.getFeature({ item: item, params: settings, propFunc: propFunc })
        );
      });
      this.addOptionals(geojson, settings);
    } else {
      geojson = this.getFeature({

this inside functions is bound to the function.

It needs to rewritten with arrow function so that this is bound to the original object:

    if (Array.isArray(objects)) {
      geojson = { type: "FeatureCollection", features: [] };
      objects.forEach((item) => {
        geojson.features.push(
          this.getFeature({ item: item, params: settings, propFunc: propFunc })
        );
      });
      this.addOptionals(geojson, settings);
    } else {

It's also good to use let or const instead of var since the latter has global scope.

Thanks for writing this as I too struck the problem of the geojson .js project not having @types. I think the better path would have been to insist https://github.com/caseycesari/GeoJSON.js rename their project and create a .dt. You seem to know them and perhaps you could have this conversation? :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions