unnecessary attributes. At the same time, the prototype chain can remain unchanged, so instanceof and isPrototypeof () can be used normally (). This is also the most ideal inheritance method currently, and is also transforming to this mode. (YUI also uses this mode .)
This blog reference JavaScript advanced programming version 3rd, the code is rewritten, more specific, and added annotations to make everyon
Object-oriented language must support the Inheritance Mechanism. One class can reuse the methods and attributes of another class.
1. Inheritance Method
Object impersonating
Working principle: the constructor uses the this keyword to assign values to all attributes and Methods. Because the constructor value is only a function, the classa constructor can be used as a classb method. Then, the classb receive
Javascrip: a small example of inheritance. For more information, see
The Code is as follows:
// InheritFunction Person (name, sex){This. name = name;This. sex = sex;}Person. prototype. sayName = function (){Alert (this. name );}Person. prototype. saySex = function (){Alert (this. sex );}Function Worker (name, sex, job){// Inherit the person classPerson. call (this, name, sex) // here this refers to the
inheritance is that it only calls the parent Type constructor once, avoiding unnecessary or unnecessary attributes. At the same time, the prototype chain can remain unchanged, so instanceof and isPrototypeof () can be used normally (). This is also the most ideal inheritance method currently, and is also transforming to this mode. (YUI also uses this mode .)
This blog reference
Agreed to explain the JavaScript inheritance, but delayed to now explain. No more nonsense, go straight to the point.
Since you want to understand the inheritance, prove that you have a certain understanding of JavaScript-oriented objects, such as what you do not understand can refer to the object-oriented JS Basic ex
());//truealert (instance2.test);//H1,h2,h3,h4Alert (Instance2.getsubvalue ());//falsealert (Instance2.color);//Pink,yellowThe above code passes through Supertype.call (this, name), inherits the properties of the parent type, through Subtype.prototype = new Supertype (), and inherits the method of the parent type. The above code is very convenient to solve the prototype chain and borrowing the problems encountered by the constructor, JavaScript is th
One- phase object inheritance mechanismToday is nothing to do, to understand the three major characteristics of object-oriented inheritance, the past learning C + + and C # are Orthodox object-oriented languageWords, the study time also did not have much in-depth understanding, just simple study the most basic inheritance. In the afternoon when looking at the
JavaScript inheritance (1) and javascript inheritanceObject-oriented and Object-based
Almost every developer has development experience in object-oriented languages (such as C ++, C #, and Java. In traditional object-oriented languages, there are two very important concepts: classes and instances. Class defines the common behaviors and methods of a class of thing
(including constructor, _ proto _ and other attributes), so no content is listed. For example:
var num=0; for(var propertyName in null) { num++; }
Alert (num); // The displayed value is 0.
The most important thing is that null has no prototype. It is not instantiated from the Object () constructor (or its subclass). If you perform the instanceof operation on it, false is returned.
2. "Empty object"
"Null Object" refers to a standard Object instan
() { this.showSub = function(a,b) { alert(a-b); } } function Class11() { this.showAdd = function(a,b) { alert(a+b); } } function Class2() { Class10.call(this); Class11.call(this); }
It's easy to implement multi-inheritance with two calls.
Of course, there are other methods to inherit js, such as using prototype chain. This does not belong to the scope of this article, but only describes the usage of call here. When we talk about call and apply, the tw
Rough exploration of the JavaScript inheritance mode and javascript inheritance
In the real sense, Javascript is not an object-oriented language and does not provide traditional inheritance methods, but it provides a prototype
JavaScript inheritance (4) and javascript inheritance
In this chapter, we will analyze Douglas Crockford's implementation of JavaScript Inheritance-Classical Inheritance in JavaScript.C
Understanding javascript Object Inheritance, and javascript Object Inheritance
First, I will study it from a question. What is javascript Object Inheritance?
For example, we have a cons
Let's talk about javascript prototype inheritance and javascript prototype inheritance.
In the real sense, Javascript is not an object-oriented language and does not provide traditional inheritance methods, but it provides a proto
Comparison of several inheritance methods in Javascript and several inheritance methods in javascriptOpening
In the 'strict' sense, javascript is not a real object-oriented language. The reason for this is that javascript, as a weak language, is very different from the
JavaScript is a prototype-based object-oriented language. That is to say, each instance object has a prototype. The object inherits attributes and methods from the prototype. This article describes the inheritance of constructor. Speaking of the basic mechanism of JavaScript prototype inheritance, this article details
JavaScript implements Multi-Inheritance Method Analysis and javascript inheritance
This example describes how to implement multiple inheritance in JavaScript. We will share this with yo
JavaScript inheritance (3) and javascript inheritance
In chapter 1, we use constructors and prototypes to implement classes and inheritance in the JavaScript world, but there are many problems. In this chapter, we will analyze the
Inheritance features in javascript and javascript inheritance features
Object-Oriented Programming Language Classification
Prototype inheritance is completed dynamically, and the method added to the prototype takes effect immediately. Even if the object instance al
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.