Skip to content

Don't pass specific options to the parent constructor #3106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2015

Conversation

fredj
Copy link
Member

@fredj fredj commented Jan 8, 2015

Same as #3104


this.setPreload(goog.isDef(options.preload) ? options.preload : 0);
this.setUseInterimTilesOnError(goog.isDef(options.useInterimTilesOnError) ?
options.useInterimTilesOnError : true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably do it w/o cloning the options object:

ol.layer.Tile = function(opt_options) {
  var options = goog.isDef(opt_options) ? opt_options : {};

  var preload = goog.isDef(options.preload) ? options.preload : 0;
  var useInterimTilesOnError = goog.isDef(options.useInterimTilesOnError) ?
      options.useInterimTilesOnError : true;

  delete options.preload;
  delete options.useInterimTilesOnError;

  goog.base(this, /** @type {olx.layer.LayerOptions} */ (options));

  this.setPreload(preload);
  this.setUseInterimTilesOnError(useInterimTilesOnError);
};

(untested)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You code works but I suggest to keep the goog.object.clone: it is how it's done in the other classes (ol.layer.Group, ol.layer.Vector, ...) and we will had to change if if/when we have a new non primitive type to handle.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You code works but I suggest to keep the goog.object.clone: it is how it's done in the other classes (ol.layer.Group, ol.layer.Vector, ...)

Ok.

and we will had to change if if/when we have a new non primitive type to handle.

We'd need to add delete statements anyway, even if clone is used. No?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need to add delete statements anyway, even if clone is used. No?

Correct.

I thought that deleting a non primitive type from an object will delete the copy too:

var obj = {
  arr: [1,2,3]
};
var c = obj.arr;
delete obj.arr;

Unlike what I was thinking: c == [1,2,3]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete just removes the property from an object. It does nothing to the object that property refers to.

@fredj
Copy link
Member Author

fredj commented Jan 12, 2015

@elemoine do you agree to merge this PR as it?

@elemoine
Copy link
Member

Yep. Please merge.

fredj added a commit that referenced this pull request Jan 12, 2015
Don't pass specific options to the parent constructor
@fredj fredj merged commit 409969f into openlayers:master Jan 12, 2015
@fredj fredj deleted the tilelayer-constr branch January 12, 2015 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants