Interesting things about the beginning of the birth of JavaScript

Source: Internet
Author: User

I have been reading a lot of good JavaScript source code when it is often the weird grammar of exhaustion, so the occasional reinforcement of the basic JavaScript is very necessary, these knowledge every time or you change the angle to think can be harvested a lot, So how is this unfathomable language born? What does its Huang think when it is created? I think if everyone knew about this history, perhaps it would be easier to understand JavaScript and feel comfortable with it, and maybe a lot of people would want to learn it well. It must be interesting to look back at the history of one thing or thing and to explore the interesting details of their history. Jurong e-Mao Steel

This is JavaScript's mountain Huang: Bremdan Eich (Brandon Aichi), now in the Mozilla Company as CTO. (The forehead is long and wide, and if Hitler is alive, he will say it is too standard Aryan).

JavaScript was born in the browser of the originator of Netscape (Netscape), about 1994 years or so, Netscape (Netscape) released the Navigator browser version 0.9, which is a very classic browser, Netscape (Netscape) The number of users so there is a blowout situation, but Navigator0.9 do not have the ability to interact with visitors, in the Internet faster than the snail is still slower than the era, Netscape The company (Netscape) urgently needs a scripting language that allows browsers and Web pages to interact to enhance the user's experience.

For this problem, Netscape (Netscape) has two options, one is to use the existing scripting language, and two is to invent a new scripting language. At that time, the high-level of Netscape (Netscape) debated the issue. In these chattering debates, time has come to 1995 years, this year has a history of the big event programming language Java was born, Java with "write once, run everywhere" powerful propaganda, the future dominated the domineering, This has enabled Netscape's Netscape to be captured by Java, as Netscape (Netscape) and Sun, Netscape (Netscape) not only allows Java programs to be embedded in the browser in the form of applets, directly inside the browser, Even the intention is to embed Java as a script into the Web page, only to find that the Web page will become too complex to give up, but JavaScript's Java imprint will never be lingering.

The turn of events took place in April 1995, when Netscape (Netscape) hired Bremdan Eich (Brandon Aichi) (although Bremdan Eich (Brandon Aichi) is JavaScript Huang, But his intervention may also be the beginning of the JavaScript tragedy. We'll keep talking about Netscape (Netscape), in May 1995, Netscape (Netscape) made a decision, the future Web scripting language must look similar to Java, but simpler than Java, so that non-professional web page authors can quickly get started.

Bremdan Eich (Brandon Aichi) was appointed to this simplified version of the Java designer. But Bremdan Eich (Brandon Aichi) had no interest in Java, and in order to cope with the company's scheduled tasks, he designed JavaScript in just 10 days. The tragedy was born.

The main direction and interest of Brendan Eich is functional programming, and the purpose of Netscape recruiting is to study the possibility of the scheme language as a scripting language for Web pages. Brendan Eich I think so, that after entering the new company, will mainly deal with scheme language. (I did not think of American companies have such a bad habit, I used to have a company very BT, especially for just graduated or not long working programmer, you want to do Java I do not give you do, let you do C #, you want to do C #, don't be naïve, you go to Daoteng Java, a lot of programmers are so disabled).

10 days the birth of a language, anyway I still put Brendan Eich as God to see. But God can not create the world too soon, we are ordinary people often do a small function module if the leader will give you 10 days, also will suffer badly, 10 days birth of a language this is not God or what ah. Because the JavaScript design time is too short, resulting in a lot of detail is poorly thought out, so the program written by JavaScript chaotic, become a lot of programmers nightmare, almost abandoned, until the advent of Ajax, so that people finally find reason to endure his deformity.

In general, the Brendan Eich design idea is this:

    1. Reference the basic grammar of C language;
    2. Learn the Java language data types and memory management;
    3. Using the scheme language, the function is promoted to the status of "First Class citizen".
    4. Use the self language for reference, using a prototype (prototype)-based inheritance mechanism.

So, the JavaScript language is actually a mixed product (Simplified) functional programming + (Simplified) object-oriented programming of two language styles. This is determined by Brendan Eich (functional programming) and Netscape (object-oriented programming).

In any case, JavaScript is related to Java, and JavaScript has Java in it. So it's not true that JavaScript has nothing to do with Java.

In fact, until now Brendan Eich still despise hate java. If it wasn't for the company's decision Brendan Eich would never have Java as a design prototype for JavaScript, even now Brendan Eich hated his work. He used to say: "I hate javascript more than I do." It is the product of the C language and the self language. The 18th century British writer Dr. Johnson said well: ' Its excellence is not original, its originality is not excellent. ”

The first time I touched JavaScript object-oriented programming, is to resist the sting and Blur to read, then just curious, insist on reading is only to maintain a good learning attitude, and at that time the JavaScript misunderstanding, I think JavaScript object-oriented programming is a code lover's game, the use of small value, but when I came into contact with some excellent JavaScript source, I found that JavaScript object-oriented programming use is so much to amaze me, Finally, it concludes that the best JavaScript code should be object-oriented.

So how does JavaScript implement inheritance? What is the inheritance mechanism of JavaScript?

First, there is no concept of "subclass" and "parent" in JavaScript, and there is no distinction between "class" and "instance" (instance), which can be inherited by a very peculiar "prototype chain" (prototype chain) pattern.

Netscape's goal in inventing and designing JavaScript, which is an important two point:

1. Simple version of Java;

2. Simple, simple or simple.

Brendan Eich introduced Java as a very important concept when designing javascript: Everything is the object. Since there are objects in JavaScript, then the design of the inheritance is troubled Brendan Eich a problem, if you really want to design a simple language can not inherit the mechanism, inheritance belongs to professional programmers, but JavaScript so many objects, If there is no mechanism, how they will be contacted, this will inevitably lead to the reliability of the program is a big problem, but the introduction of inheritance and will use JavaScript into a complete object-oriented language, thus improving its threshold, so that many beginners to deter, compromise, Brendan Eich still choose design inheritance, but is not the standard inheritance (said here I think of the same use of Emcascript standard design language ActionScript, it has a very complete inheritance, it is very comfortable to do, I often think this is not JavaScript after the trend, Maybe one day JavaScript will become 搄 more perfect to write? )。 The tradeoff is that Brendan Eich does not intend to introduce classes (class), so that JavaScript at least looks like an object-oriented language, so beginners will not be deterred (this is cheating ah, come in and daoteng you, this is called Alec).

Brendan Eich after thinking, decided to draw on C + + and Java's new command, the new command introduced JavaScript, in the traditional object-oriented language, new is used to construct the instance object, new calls the constructor, but the traditional object-oriented language new is the class , the internal mechanism is called the constructor (constructor), and Brendan Eich simplifies this operation, in JavaScript, new is directly behind the constructor, so we can write a person class like this:

1 functionPerson(name)
2 {
3     this.name = name;
4 }
5
6 varper = newPerson(‘Brendan Eich‘);
7 console.log(per.name);//Brendan Eich

This creates a new instance. But new is flawed. Generating an instance object with a constructor cannot fail to share properties and methods, such as the following code:

01 functionPerson(name)
02 {
03     this.name = name;
04     this.nation = ‘USA‘;
05 }
06
07 varper1 = newPerson(‘Brendan Eich‘);
08 varper2 = newPerson(‘IT民工‘);
09 per2.nation = ‘China‘;
10 console.log(per1.nation);//USA
11 console.log(per2.nation);//China

Each instance object has its own copy of the properties and methods. This not only can not do data sharing, but also a huge waste of resources. As with the shortcomings of the JavaScript factory model, too many duplicate objects can slow down the browser, resulting in a huge waste of resources.

With this in mind, Brendan Eich decides to set a prototype property for the constructor, which is a pointer to a prototype object. The following sentence is important: all instance objects need to share properties and methods that are placed inside the object, and those that do not need to be shared are placed inside the constructor.

Once the instance object is created, the properties and methods of the prototype object are automatically referenced. In other words, the properties and methods of an instance object are divided into two types, one local and the other referenced. If we can rewrite the above program:

01 functionPerson(name)
02 {
03     this.name = name;
04 }
05
06 Person.prototype = {nation:‘USA‘};
07
08 varper1 = newPerson(‘Brendan Eich‘);
09 varper2 = newPerson(‘IT民工‘);
10
11 console.log(per1.nation);//USA
12 console.log(per2.nation);//USA

When we write programs like this Person.prototype.nation = ' China '; The nation of all instantiated classes will become China.

Since all instance objects share the same prototype object, it appears from the outside that the prototype object is like a prototype of an instance object, and the instance object is like "inheriting" the prototype object. Prototype just provides a convenient way and means to implement JavaScript inheritance.

Interesting things about the beginning of the birth of JavaScript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.