Repository navigation
question: remove required new operator #172
Description
Activity
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
newsince they are instantiating an object.I don't think it would hurt, however, to add in the if to catch non-instantiating executions.
Yeah, makes sense. I didn't know JSHint would do this.
I've come around. Me, from #168:
It feels like forcing the developer to use
newis 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 sayinggcloud.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({});
var gcloud = require('gcloud'); var dataset = gcloud.datastore.dataset({}); var bucket = gcloud.bucket({});
😍
Oops, had to update my comment. Hope you still like it:
-var bucket = gcloud.bucket({}); +var bucket = gcloud.storage.bucket({});
Didn't notice that mistake. Yes, that makes more sense and still looks perfect.
- added a commit that references this issue
on Sep 15, 2014 - added a commit that references this issue
on Aug 22, 2022 - added a commit that references this issue
on Sep 15, 2022 69 remaining items
- added a commit that references this issue
on Mar 5, 2026 - added 2 commits that reference this issue
on Mar 5, 2026 - added 2 commits that reference this issue
on Mar 9, 2026 - added a commit that references this issue
on Mar 11, 2026 - added a commit that references this issue
on Mar 12, 2026 - added 2 commits that reference this issue
on Mar 12, 2026 - added 2 commits that reference this issue
on Mar 23, 2026 - added a commit that references this issue
on Mar 27, 2026 - added a commit that references this issue
on Mar 27, 2026 - added a commit that references this issue
on May 5, 2026
In addition to this:
can we support (note the lack of the
newkeyword):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 change was to be made, I would suggest that developers omit
newalways 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 ofDatasetimplies its a constructor but they can call it just like a regular method ondatastore.Thoughts?