1. Object Impersonation
function Parent (username) { this.username = Username; This.hello = function () { alert (this.username); }} function Child (Username,password) { ///By appending the properties and methods of the parent to the child through the following 3 line implementations to implement the integration implementation inheritance //1. This.method is a temporary property and points to the object that the parent points to, //2. Executes the This.method method, which is the object function//3 that the parent points to . Destroys the This.method attribute, which means that at this point the child has all the properties and methods of the Parent This.method = Parent;this.method (username);//Key row Delete This.method ; this.password = password; This.world = function () { alert (This.password); }} var parent = new Parent ("Zhangsan"), var child = new Child ("Lisi", "123456");p Arent.hello (); Child.hello (); Child.world (); 2. Inherit the second way: Call () method call method is a method in the function class The value of the first parameter of the all method is assigned to the class (that is, the method) in the second argument of the ThisCall method that occurs in order to assign a value to the class (that is, the method) the parameters accepted
3. Third Way of inheritance: Apply () method
The Apply method accepts 2 parameters
A. The first parameter is the same as the first parameter of the call method, which is assigned to the this that appears in the class (that is, the method)
B. The second parameter is an array type, in which each element in the sequence is assigned to a parameter that is accepted by the class (that is, the method)
4. Fourth way: The prototype chain, that is, the subclass prototype all the attributes and methods appended by prototype in the parent class to child, thus implementing the inheritance.
5. Fifth way of inheritance: Hybrid mode
Mixed call mode, prototype chain way.
There are 5 ways to implement JavaScript inheritance