Skip to content
This repository has been archived by the owner on Dec 30, 2019. It is now read-only.

[Q] String#{trimStart, trimEnd} and String#{trimLeft, trimRigth} equality #4

Closed
zloirock opened this issue Nov 19, 2015 · 7 comments
Closed

Comments

@zloirock
Copy link

Is it the same functions? If the same - which names they should have?

String.prototype.trimStart === String.prototype.trimLeft; // ???
String.prototype.trimStart.name; // ???
String.prototype.trimLeft.name; // ???
@ljharb
Copy link
Member

ljharb commented Nov 19, 2015

That's a good question. The options are either:

  • they are !==
  • they are === and their names are trimStart/trimEnd
  • they are === and their names are trimLeft/trimRight

I think that the easiest as well as the one that ends up with the preferred names is the first option - where they are different functions but both call the same internal abstract operation.

@zloirock
Copy link
Author

The first way the easiest, but currently in the spec if functions do the same - it's the same functions. Simple example - Set#{keys, values, @@iterator}.

@ljharb
Copy link
Member

ljharb commented Nov 20, 2015

That's a good point. Based on that pattern, it'd be one of the second two - probably the third option for easier legacy compat.

@zloirock
Copy link
Author

Agree.

@sebmarkbage ?

@claudepache
Copy link
Contributor

FWIW, Date.prototype.toGMTString === Date.prototype.toUTCString is true (with name "toUTCString") in Firefox and ES2015, but false in Chrome, Safari (with names "toGMTString" and "toUTCString") and IE (without name).

If we seek spec consistency with that precedent, the option "=== w/ names trimStart/trimEnd" should be picked. Also, I don’t think there is much compat issue around the name of these functions, since functions in IE11 have no name.

Anyway, personally I don’t care, as long as the "official" function (trimStart) gets the "correct" name ("trimStart").

@evilpie evilpie mentioned this issue Apr 7, 2016
8 tasks
@ljharb
Copy link
Member

ljharb commented Apr 7, 2016

The current spec makes trimStart and trimEnd be the canonical functions with the appropriate name, which are === to trimLeft/trimRight.

@evilpie
Copy link
Collaborator

evilpie commented Apr 29, 2016

I think we can close this for now. If this for some reason is causing concern at the meeting we can reopen the issue.

@evilpie evilpie closed this as completed Apr 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants