GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — question: remove required new operator · Issue #172 · googleapis/google-cloud-node

question: remove required new operator #172

New issue
Copy link
New issue
Copy link
Closed
Closed
question: remove required new operator#172
Copy link
Assignees
stephenplusplus
Labels
coretype: questionRequest for information or clarification. Not an issue.
Milestone
Core Stable

Description

@ryanseys
ryanseys
opened on Sep 3, 2014
Issue body actions

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?

Activity

Next
  1. ryanseys
    added
    question
    on Sep 3, 2014
  2. stephenplusplus commented on Sep 4, 2014

    @stephenplusplus
    stephenplusplus
    on Sep 4, 2014
    Contributor
    More actions

    Why?

    If their codebase is using JSHint (and probably other linters), they'll have to explicitly turn off the recommendation of capital character referring to something that should be new'd. I'm in favor of continuing to use the new behavior, because hiding it is unnecessary confusion, which only has the purpose of avoiding using "new". I think it's best we stick to the convention and recommend using new since they are instantiating an object.

    I don't think it would hurt, however, to add in the if to catch non-instantiating executions.

  3. ryanseys commented on Sep 5, 2014

    @ryanseys
    ryanseys
    on Sep 5, 2014
    ContributorAuthor
    More actions

    Yeah, makes sense. I didn't know JSHint would do this.

  4. stephenplusplus commented on Sep 6, 2014

    @stephenplusplus
    stephenplusplus
    on Sep 6, 2014
    Contributor
    More actions

    I've come around. Me, from #168:

    It feels like forcing the developer to use new is important for them to understand "you're getting a new object that is meant to be multiply instantiated," but I suppose you can argue that that's an implementation detail of how our internal structure works, and saying gcloud.datastore.dataset(), for example, can be just as clear, especially with the help of the documentation.

    I would be interested in hearing what @rakyll and others think about facading our internal use of new, creating an end-user api like:

    var gcloud = require('gcloud');
    var dataset = gcloud.datastore.dataset({});
    var bucket = gcloud.storage.bucket({});
  5. ryanseys commented on Sep 6, 2014

    @ryanseys
    ryanseys
    on Sep 6, 2014
    ContributorAuthor
    More actions
    var gcloud = require('gcloud');
    var dataset = gcloud.datastore.dataset({});
    var bucket = gcloud.bucket({});

    😍

  6. stephenplusplus commented on Sep 6, 2014

    @stephenplusplus
    stephenplusplus
    on Sep 6, 2014
    Contributor
    More actions

    Oops, had to update my comment. Hope you still like it:

    -var bucket = gcloud.bucket({});
    +var bucket = gcloud.storage.bucket({});
  7. ryanseys commented on Sep 6, 2014

    @ryanseys
    ryanseys
    on Sep 6, 2014
    ContributorAuthor
    More actions

    Didn't notice that mistake. Yes, that makes more sense and still looks perfect.

  8. stephenplusplus
    added a commit that references this issue on Sep 15, 2014

    feat(app): support global configuration

    This issue will close once commit 611f7f2 is merged into the 'master' branch.
    611f7f2
  9. stephenplusplus
    closed this as completedin 611f7f2on Sep 16, 2014
  10. jgeewax
    added
    core
    on Feb 2, 2015
  11. jgeewax
    added this to the Core Stable milestone on Feb 2, 2015
  12. JustinBeckwith
    assigned
    stephenplusplus
    on Feb 1, 2021
  13. chingor13
    added a commit that references this issue on Aug 22, 2022

    docs: document apiEndpoint over servicePath (#172)

    94ab074
  14. sofisl
    added a commit that references this issue on Sep 15, 2022

    refactor: drop dependency on lodash.merge and update links (#172)

    f32d4b3
  15. 69 remaining items

  16. codyoss
    added a commit that references this issue on Mar 5, 2026

    feat!: drop Node 8 from engines field (#172)

    3c70617
  17. sofisl
    added 2 commits that reference this issue on Mar 5, 2026

    chore(deps): update dependency nyc to v14

    48a1b22

    chore(deps): update dependency @types/uuid to v8 (#172)

    7008d66
  18. codyoss
    added 2 commits that reference this issue on Mar 9, 2026

    chore: regenerate synth.metadata (#172)

    bcaf4e1

    chore: regenerate synth.metadata (#172)

    7edfaad
  19. GautamSharda
    added a commit that references this issue on Mar 11, 2026

    chore(deps): lock file maintenance (#172)

    dab4525
  20. codyoss
    added a commit that references this issue on Mar 12, 2026

    chore: Report warning on `.github/workflows/ci.yaml` (#172)

    d3f22a1
  21. GautamSharda
    added 2 commits that reference this issue on Mar 12, 2026

    chore: update jsdoc.js (#172)

    813b738

    chore: update jsdoc.js (#172)

    c6e2378
  22. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    Update gcs-resumable-upload to the latest version 🚀 (googleapis#172)

    ac1d7d4
  23. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    change id vs. name in Cluster (#172)

    1eb6938

    change id vs. name in Cluster (#172)

    3a65276
  24. feywind
    added a commit that references this issue on Mar 27, 2026

    chore(deps): lock file maintenance (#172)

    64e07dc
  25. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    change id vs. name in Cluster (#172)

    0613c89
  26. thiyaguk09
    added a commit that references this issue on May 5, 2026

    change id vs. name in Cluster (googleapis#172)

    ded6f76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

Labels

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

Type

No type

Projects

No projects

    Milestone

    • Core Stable

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.