Skip to content

question: remove required new operator #172

@ryanseys

Description

@ryanseys

In addition to this:

dataset = new datastore.Dataset({
  projectId: 'my-project',
  keyFilename: '/path/to/keyfile.json'
});

can we support (note the lack of the new keyword):

dataset = datastore.Dataset({
  projectId: 'my-project',
  keyFilename: '/path/to/keyfile.json'
});

We can accomplish this by a technique discussed here.

Essentially detect whether the object calling it is an instance of Dataset or not:

if ( !(this instanceof Dataset) ) {
  return new Dataset();
}

If this change was to be made, I would suggest that developers omit new always and we don't document it as requiring it in the first place as it simplifies what the developer needs to worry about. The capitalization of Dataset implies its a constructor but they can call it just like a regular method on datastore.

Thoughts?

Metadata

Metadata

Labels

coretype: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions