Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Throw if CTOR without new #24

Merged
merged 1 commit into from
Mar 17, 2017
Merged

Throw if CTOR without new #24

merged 1 commit into from
Mar 17, 2017

Conversation

zbraniecki
Copy link
Member

I believe we should be throwing if constructor called without new.

@zbraniecki
Copy link
Member Author

@caridy ?

@littledan
Copy link
Member

What's the motivation for this? IIRC @thetalecrafter suggested the opposite at some point.

@vanwagonet
Copy link

Throwing without new is the current behavior for Map, Set, and user-defined classes. Personally, I really dislike this behavior, but admit I have no concrete argument against it in general.

Intl.{Collator,DateTimeFormat,NumberFormat} construct a new instance even without new, much like Array or Error. I think consistency with other Intl.* constructors would be good, and changing them to throw without new is probably a web-breaking change. (At least I've written a fair amount of code that use Intl without new.)

@zbraniecki
Copy link
Member Author

Hah, I'm the total opposite, so yeah, it's a matter of preference.

I love the Map and Set behavior and believe that @caridy wanted us to follow that for all new classes. That's why we aimed for this in PluralRules and all future formatters.

@vanwagonet
Copy link

Preferences aside, it's probably a lot safer to start with throwing if called without new. If we decide there is a great use for calling as a function later, it's more likely to be web compatible than trying the other way.

@vanwagonet
Copy link

It also allows a polyfill to define it with a class.

@littledan
Copy link
Member

Being consistent with classes was a big piece of motivation for throwing for other new objects in ES, so it makes sense to apply that here.

@caridy caridy merged commit dbd0de4 into tc39:master Mar 17, 2017
@caridy
Copy link
Collaborator

caridy commented Mar 17, 2017

@zbraniecki don't commit the generated HTML, that makes the review more difficult, and more conflict-prompt anyways. we can generate the HTML from time to time.

@littledan
Copy link
Member

@caridy For repositories I maintain, I regenerate the HTML on each commit. This makes it easier for me and others to see the most recently rendered version. I check in the HTML into the gh-pages branch of the same repository, so it doesn't mess up the history of any other branch and so it's automatically on GitHub pages.

I believe @bterlson has a nice setup where Travis-CI does this build for him. I haven't taken the time to set that up for my repos yet; maybe it would be a nice thing to document in @ljharb's repository template eventually.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants