js is a language based on prototypal inheritance. At the beginning of the creation, I referred to Scheme, which uses functions as first-class citizens, the syntax of C language, and the prototypal inheritance of self language, so it is a combination of the advantages of the three; it was originally called LiveScript, but Java was very popular at the time, so the company changed its name. It's called JavaScript, but actually it has nothing to do with java. The advantage of prototypal inheritance is that it allows multiple inheritance and can simulate classes, but class languages can never simulate prototypes. This is the flexibility of JavaScript, which can be used for both functional programming and object-oriented programming.
Classes and objects in JavaScript are inherently controversial because they use prototypal inheritance, which is inheritance achieved by referencing methods on the prototype chain. The methods on the object you call will ultimately call the methods above Object.prototype. Even if these methods are not defined using new but are defined using object literals, they can still be called. That is, if you modify the method on Object.prototype, then the method called by all objects will change. All constructors in JavaScript are actually faked using prototypal inheritance. Even the newly added class in ES6 is essentially implemented using prototypal inheritance. So we still need to have a deeper understanding of how prototypal inheritance is implemented.
js is a language based on prototypal inheritance. At the beginning of the creation, I referred to Scheme, which uses functions as first-class citizens, the syntax of C language, and the prototypal inheritance of self language, so it is a combination of the advantages of the three; it was originally called LiveScript, but Java was very popular at the time, so the company changed its name. It's called JavaScript, but actually it has nothing to do with java.
The advantage of prototypal inheritance is that it allows multiple inheritance and can simulate classes, but class languages can never simulate prototypes. This is the flexibility of JavaScript, which can be used for both functional programming and object-oriented programming.
http://www.cnblogs.com/wangfu...
Classes and objects in JavaScript are inherently controversial because they use prototypal inheritance, which is inheritance achieved by referencing methods on the prototype chain. The methods on the object you call will ultimately call the methods above
Object.prototype
. Even if these methods are not defined usingnew
but are defined using object literals, they can still be called.That is, if you modify the method on
Object.prototype
, then the method called by all objects will change. All constructors in JavaScript are actually faked using prototypal inheritance. Even the newly addedclass
in ES6 is essentially implemented using prototypal inheritance. So we still need to have a deeper understanding of how prototypal inheritance is implemented.