The history of JavaScript

  • JavaScript was originally designed by Netscape’s Brendan Eich.
  • JavaScript is a registered trademark of Oracle corporation.
  • Ecma International develops the ECMAScript standard based on JavaScript.
  • JavaScript can also be used in other contexts, such as server-side programming. The complete JavaScript implementation consists of three parts: ECMAScript, document Object Model, and browser object Model.
  • Netscape originally named its scripting language LiveScript, which Netscape later renamed JavaScript after partnering with Sun. JavaScript was originally designed to be Inspired by Java, in part to “look like Java,” so there are syntactic similarities, and some names and naming conventions are borrowed from Java. The similarity between JavaScript and Java names was the result of an agreement Netscape struck with Sun Microsystems for marketing purposes at the time.
  • But the main design principles of JavaScript come from Self and Scheme.
  • In the early stage of development, the standard of JavaScript was not determined. There were Netscape’S JavaScript, Microsoft’s JScript and CEnvi’s ScriptEase at the same time. In 1997, under the coordination of ECMA (European Computer Manufacturers Association), a working group composed of Netscape, Sun, Microsoft and Borland decided on a unified standard: ECMA-262.

JavaScript were born

Explain how Javascript was designed from a historical perspective. Only by understanding this history can you understand why Javascript is the way it is.

In 1994, Netscape released version 0.9 of its Navigator browser. It was the first full-fledged web browser in history, and it was a hit. However, this version of the browser can only be used for browsing and does not have the ability to interact with visitors. . Netscape desperately needed a web scripting language that would allow browsers to interact with the web.

In April 1995, Netscape hired Brendan Eich, a 34-year-old systems programmer. Brendan Eich’s primary interest and interest is functional programming, and netscape recruited him to investigate the possibility of using the Scheme language as a web scripting language. Brendan Eich himself felt the same way, assuming that he would be working primarily with Scheme when he arrived at his new company.

In May 1995, just a month later, Netscape decided that the web scripting language of the future would have to “look similar enough to Java” but be simpler enough to make it accessible to non-professional web authors. This decision effectively excludes non-object-oriented programming languages such as Perl, Python, Tcl, and Scheme.

Brendan Eich was designated as the designer of this “simplified Version of the Java language.”

However, he has no interest in Java at all. He designed Javascript in just 10 days to meet the company’s demands.

Because the design time was too short, some of the details of the language were not carefully considered, resulting in a long time later, Javascript written programs chaotic. If Brendan Eich had foreseen a future in which this language would be the number one language on the Internet, with millions of learners worldwide, would he have taken a little more time?

In general, his design idea goes like this:

  1. Learn from the basic syntax of C language;
  2. Using the Java language for data types and memory management;
  3. Using Scheme language to elevate functions to the status of “first class”;
  4. Reference Self language, using prototype – based inheritance mechanism.

So the Javascript language is really a hybrid of the two language styles —- (simplified) functional programming + (simplified) object-oriented programming. This was decided by Brendan Eich (functional programming) and Netscape (object-oriented programming).

10 Design Flaws with JavaScript

Why does Javascript have design flaws?

There are three objective reasons why Javascript design isn’t perfect.

  1. The design phase was too hasty.

    Javascript was designed in ten days. Moreover, the designer is to deliver to the company, I do not want to design so.

    The language, on the other hand, was designed to handle simple web interactions (such as checking “username”) without considering the needs of complex applications. Designers never dreamed that Javascript would be able to create web pages as large and complex as Gmail.

  2. Without precedent

    Javascript combines both functional and object-oriented programming, possibly for the first time in history. And to this day, Javascript remains the only major language in the world that uses the Prototype inheritance model. This leaves it with no design precedent to follow.

  3. Premature standardization

    Javascript moves so fast that there is no time to tweak the design.

    In May 1995, the design plan was finalized; In October, the interpreter was developed successfully. It was introduced to the market in December and was immediately widely accepted by users around the world. Javascript lacks a process of growing from small to large, slowly accumulating users, but rather a continuous, explosive proliferation of growth. The large number of established web pages and amateur web designers make it difficult to adjust the language specification.

    To make matters worse, the Javascript specification has not yet been adjusted and solidified.

    In August 1996, Microsoft intervened strongly and announced the launch of its own scripting language Jscript. In November netscape decided to apply for an international standard for Javascript in order to thwart Microsoft. In June 1997, the first international standard ecMA-262 was formally promulgated.

    In other words, a year and a half after Javascript came out, there was an international standard. Design flaws were standard before they were fully exposed. C, by contrast, came nearly 20 years before an international standard was issued.

10 Design Flaws of Javascript

  1. Not suitable for developing large programs

    Javascript has no namespace and is difficult to modularize; There is no specification for how to distribute code across multiple files; Allows for duplicate definitions of functions with the same name, with the latter overwriting the previous, making modular loading difficult.

  2. Very small standard library

    The standard library of functions provided by Javascript is very small and can only do a few basic operations, with many functions lacking.

  3. Null, and undefined

    Null is a type of object, meaning that the object is empty. Undefined is a data type, meaning undefined.

typeof null; // object
typeof undefined; // undefined
Copy the code

It’s very confusing, but it has very different meanings.

var foo;
alert(foo == null);// true
alert(foo == undefined);// true
alert(foo === null);// false
alert(foo === undefined);// true
Copy the code

Null is almost useless in programming practice and should never have been designed.

  1. Global variables are difficult to control

    Javascript global variables, visible in all modules; Global variables can be generated inside any function, which greatly increases the complexity of the program.

a = 1;
(function(){
    b=2; alert(a); }) ();/ / 1
alert(b); / / 2
Copy the code
  1. Automatic insertion of end-of-line semicolons

    All Javascript statements must end with a semicolon. However, if you forget to add a semicolon, the interpreter does not report an error, but automatically adds a semicolon for you. Sometimes, this leads to errors that are hard to spot.

    For example, the following function does not achieve the desired result at all. Instead of returning an object, it returns undefined.

function(){
    return
    {
        i=1
    };
}
Copy the code

The reason is that the interpreter automatically adds a semicolon to the return statement.

function(){
    return;
    {
        i=1
    };
}
Copy the code
  1. The plus operator

    As an operator, the + sign has two meanings. It can represent the sum of numbers or the concatenation of characters. Such a design unnecessarily increases the complexity of the operation, and a separate concatenation operator can be set up.

  2. NaN

    NaN is a number that indicates that the interpreter has exceeded its limits. It has some very strange properties:

NaN= = =NaN; //false
NaN! = =NaN; //true
alert( 1 + NaN ); // NaN
Copy the code

Instead of designing NaN, the interpreter can simply report errors.

  1. Distinction between arrays and objects

    Since Javascript arrays are objects, it can be tricky to tell whether an object is an array or not.

  2. = = and = = =

    == is used to determine whether two values are equal. When two value types are different, an automatic conversion occurs, and the result is very counterintuitive.

    Therefore, it is recommended to use the “===” (exact judgment) comparator at all times.

  3. Wrapper object of basic type

    Javascript has three basic data types: strings, numbers, and Booleans. They all have constructors that generate string objects, number objects, and Booleans.

    new Boolean(false);
    new Number(1234);
    new String("Hello World");
    Copy the code

    The object types that correspond to the base data types are of little use but of great confusion.

    alert( typeof 1234); // number
    alert( typeof new Number(1234)); // object
    Copy the code

How do you view the design flaws of Javascript?

Given Javascript’s flaws and its abundance, is it a bad language? Is there a future?

The answer is that Javascript isn’t bad, but rather powerful and promising.

First, most of these pitfalls of Javascript can be avoided if good programming practices are followed, with the help of third-party libraries.

Second, Javascript is currently the only language for web programming, and as long as the web continues to evolve, so will it. Node.js makes Javascript available for back-end server programming, and coffeeScript lets you write Javascript using Python and Ruby syntax.

Finally, these design flaws can be remedied by simply releasing a new version of the language standard, such as ECMAscript 5. Of course, publishing a standard and implementing a standard are two different things, and many of the flaws mentioned above will probably remain with Javascript until the last day of its existence.