Skip to content
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

Changes to keep aligned with discussion #76

Closed
wants to merge 7 commits into from

Conversation

pipobscure
Copy link
Collaborator

I named the method .asString() for now, but that should be name-checked (open for suggestions). I really don't like toISOString() because that suggests generi ISO. However the string produced has quite detailed specification in order to clarify fromString(). (Maybe I'm just too hestitant, but it just gives me heebe-jeebies)

@littledan
Copy link
Member

Bikeshed: We don't have anything in the standard library with the as prefix; I'd think about other names which start with to.

@pipobscure
Copy link
Collaborator Author

pipobscure commented Aug 2, 2018

@littledan I agree, but to is already taken to be the loggable/debuggable string 😄

That's why I'm asking for better names!

Currently I have both .toString() and .asString()

Oh and making it as has the benefit that no one will accept it and therefore renaming will be almost guaranteed 👍

const { year, month, day } = this;
return `${spad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}`;
}
toString() {
return `[object CivilDate ${this.asString()}]`;
Copy link
Member

Choose a reason for hiding this comment

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

This is a very strange result that I think would be a bad idea. If it's going to be in the [object X] form, it should follow that convention.

Rather than defining a toString, it would probably want get [Symbol.toStringTag]() { return CivilDate ${this.asString(); } - but I'd still think this is way less useful than returning the previous toString implementation.

@@ -13,25 +13,40 @@ export class CivilDate {
const { year, month, day } = plus({}, { years, months, days });
this[DATA] = { year, month, day };
}
get [Symbol.toStringTag] () { return 'CivilDate'; }
Copy link
Member

Choose a reason for hiding this comment

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

these shouldn’t be getters (unless they’re going to brand check before returning the string, which I’d be super in favor of)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why? What?

Since class public fields are not a thing yet, ...
Also what do you mean by "brand check"? Check that it's an instance of ?
Explain, I'm confused.

Copy link
Member

Choose a reason for hiding this comment

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

Since class fields aren’t a thing yet, it simply can’t live inside the class body. You’d want to do CivilDate.prototype[Symbol.toStringTag] = ‘CivilDate’; after the class definition.

A brand check would be if it threw, or returned null, when the receiver lacked the right internal slot - in other words, if you did new CivilDate()[Symbol.toStringTag] you’d get ’CivilDate’, but if you did CivilDate.prototype.toStringTag it would throw.

@ljharb
Copy link
Member

ljharb commented Aug 3, 2018

I still think the polyfill code here should be removed from this repo and moved to a separate one.

@pipobscure
Copy link
Collaborator Author

@ljharb right now having them together is very useful, since it's easier to develop the spec and the polyfill concurrently, one bouncing off the other. At the same time I'm with you as regards to making it easier to publish to npm.

We should also probably schedule another live call, with everyone there, and have the discussion verbally to hash it out.

@domenic
Copy link
Member

domenic commented Aug 3, 2018

No, don't make Symbol.toStringTag a brand-checked getter, that's inconsistent with the rest of JavaScript. Just do what evertyhing else does...

@pipobscure
Copy link
Collaborator Author

obsolete due to #88

@pipobscure pipobscure closed this Sep 21, 2018
@pipobscure pipobscure deleted the polyfill3 branch June 4, 2019 08:48
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.

5 participants