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

Historical info #10

Closed
hax opened this issue Jan 26, 2022 · 2 comments
Closed

Historical info #10

hax opened this issue Jan 26, 2022 · 2 comments

Comments

@hax
Copy link
Member

hax commented Jan 26, 2022

"Why we invented String.p.split like that" was asked in the meeting. So I suppose there are also people interest in this topic. Maybe it could be added to README.


When we have JSCIG meeting last week, the same question is asked and @aimingoo did a quick research, here is the info:

  1. ES1 (1997/6) and ES2 do not have split with the second arg
  2. ES3 add it

And I did some test:

  1. NN3(1996/8) do not have second arg
  2. NN4(1997/6) has it
  3. IE4(1997/10) do not have it

So my conclusion is:

  1. The second arg was added by Netscape in some point from 1996/8 to 1997/6.
  2. This API is not from Java, because Java only add String.split in 1.4 (2002)
  3. It seems TC39 just added it to ES3 as NN4 behavior.
@lucacasonato
Copy link
Member

Thanks for doing the research on this. Added the historical context in a8936e0.

@hax
Copy link
Member Author

hax commented Apr 2, 2022

Today I happened to read some code of old netscape navigator, and as the code and comments tell, js split is definitely coming from Perl. But Brendan just implemented the simplest version (split(string)) in the beginning.

JavaScript 1.2 added regexp and follow the re capture as Perl, and even some special perl behavior: " a b c ".split(' ') would return ['a', 'b', 'c'] (behave like .trim().split(/\s+/)). So I believe the plan was also implement the limit param just as perl. The old "New in JS 1.2" documentation even said:

It can take a limit count so that it won't include trailing empty elements in the resulting array.

The sentence only make sense if follow perl behavior (when limit is omit or 0, strip empty elements).

Unfortunately, for unknown reason (may be no enough time, or just forgot), netscape engineers didn't fully implement it...

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

No branches or pull requests

2 participants