The Birth of Javascript
1.
Two weeks ago, I talked a little about the history of Javascript.
Today I will complete this part and explain how Javascript was designed from a historical perspective.
Only by understanding this history can we understand why Javascript is what it is now. The information I rely on is mainly Brendan Eich’s self- report .
2.
The previous article wrote:
“In 1994, Netscape released version 0.9 of the Navigator browser. This was the first relatively mature web browser in history, and it was a sensation. However, this version of the browser can only be used for browsing and does not have The ability to interact with visitors… Netscape urgently needs a web scripting language that allows browsers to interact with web pages. ”
What kind of language is web scripting language? Netscape had two options at the time: one was to adopt existing languages, such as Perl, Python, Tcl, Scheme, etc., and allow them to be embedded directly into web pages; the other was to invent a new language.
Both options have their pros and cons. The first option is conducive to making full use of existing code and programmer resources, and it is easier to promote; the second option is conducive to the development of a fully applicable language, which is easier to implement.
As to which option to use, Netscape’s internal disputes are over, and it is difficult for the management to make up their minds for a while.
3.
Just then, another major event happened: In 1995, Sun changed the Oak language to Java and officially launched it on the market.
Sun hyped, promising that this language can be “Write Once, Run Anywhere” (Write Once, Run Anywhere), and it looks likely to become the master of the future.
Netscape was moved and decided to form an alliance with Sun. It not only allows Java programs to run directly in the browser in the form of applets (small programs); it even considers embedding Java as a scripting language directly into web pages, only because this would make HTML web pages too complicated, and later had to give up.
In short, the situation at the time was that the entire management of Netscape was a believer in the Java language, and Sun was completely involved in the decision-making of the web scripting language. Therefore, Javascript was later brought to the market by Netscape and Sun. It is not accidental that this language was named “Java+script”.
4.
At this time, the 34-year-old system programmer Brendan Eich debuted. In April 1995, Netscape hired him.
Brendan Eich’s main direction and interest is functional programming. Netscape recruited him for the purpose of studying the possibility of using Scheme language as a web scripting language. Brendan Eich himself thought the same way, thinking that after entering the new company, he would mainly deal with the Scheme language.
Just a month later, in May 1995, Netscape made a decision that the future web scripting language must “look sufficiently similar to Java”, but simpler than Java, so that non-professional web page authors can quickly get started. This decision actually excludes non-object-oriented programming languages such as Perl, Python, Tcl, and Scheme.
Brendan Eich has been designated as the designer of this “simplified version of the Java language”.
5.
However, he has no interest in Java at all. In order to cope with the tasks arranged by the company, he designed Javascript in only 10 days.
Due to the short design time, some details of the language were not considered rigorously, leading to a long period of time afterwards, the program written in Javascript was chaotic. If Brendan Eich foresees that this language will become the number one language on the Internet in the future, with millions of learners around the world, will he spend a little more time?
In general, his design ideas are as follows:
(1) Learn from the basic grammar of C language;
(2) Drawing lessons from the data types and memory management of the Java language;
(3) Learning from Scheme language, the function is promoted to the status of “first class” (first class);
(4) Learn from the Self language and use a prototype-based inheritance mechanism.
Therefore, the Javascript language is actually a mixture of two language styles-(simplified) functional programming + (simplified) object-oriented programming. This was decided jointly by Brendan Eich (functional programming) and Netscape (object-oriented programming).
6.
Many years later, Brendan Eich still looks down on Java.
He said:
“The impact of Java (on Javascript) is mainly to divide data into primitive and object types, such as strings and string objects, and introduce Y2K problems. This is really unfortunate.”
Whether it is advisable to pack basic data types into objects is a matter for the time being. The Y2K problem is directly related to Java. According to the assumption, Date.getYear() should return the last two digits of the year:
var date1 = new Date(1999,0,1);
var year1 = date1.getYear();
alert(year1); // 99
But in fact, for the year 2000, it returned 100!
var date2 = new Date(2000,0,1);
var year2 = date2.getYear();
alert(year2); // 100
If you use this function to generate the year, some web pages may have a result such as “19100”. This problem comes from Java completely, because the date class of Javascript directly uses the java.util.Date library. Brendan Eich was obviously dissatisfied with this result, which led to the later having to add a Date.getFullYear() function that returns a four-digit year.
If it were not for the company’s decision, Brendan Eich would never have used Java as a prototype for Javascript design. As a designer, he doesn’t like his work at all:
“It is better to say that I hate Javascript than I love Javascript. It is the product of one-night stand of C language and Self language. The 18th century English writer Dr. Johnson said it well: “Its excellence is not original, its originality Not excellent.’ (the part that is good is not original, and the part that is original is not good.)”
(over)