Discover javascript class vs prototype, include the articles, news, trends, analysis and practical advice about javascript class vs prototype on alibabacloud.com
In JavaScript play inheritance (II), I used the prototype inheritance method to implement JavaScript inheritance. What is the mysteries of prototype. In this articleArticleI will discuss the prototype.
Aside from JavaScript, Let
A deep understanding of javascript prototype chain and inheritance, and a deep understanding of javascript
In the previous article, I introduced the concept of prototype and learned the relationship among the three friends in javascript: constructor,
A good explanation of JavaScript inheritance, but slow to explain now. Don't say much nonsense, go straight to the chase.Since you want to understand the inheritance, prove that you have a certain understanding of JavaScript object-oriented, such as what is not understood can refer to the "Object-oriented JS basic explanation, Factory mode, constructor mode, prototype
As mentioned in the article on JavaScript creation objects: One problem with creating objects with constructors is that the same method for different instances of the same constructor is not the same, so we use prototypes to extract the public properties and methods of the constructor for encapsulation. Achieve the purpose of having all instances shared.Next you'll learn more about JavaScript prototypes.Fir
Each function created in JavaScript has a prototype (prototype) attribute, which is a pointer to an object that is used to contain properties and methods that can be shared by all instances of a particular type. If the literal meaning is understood, then prototype is the prototype
A good explanation of JavaScript inheritance, but slow to explain now. Don't say much nonsense, go straight to the chase.Since you want to understand the inheritance, prove that you have a certain understanding of JavaScript object-oriented, such as what is not understood can refer to the "Object-oriented JS basic explanation, Factory mode, constructor mode, prototype
Special attention should be paid to reading and modifying the prototype in javascript, because the reading and writing of the prototype is not equivalent.
For members inherited from prototype objects, the read and write operations are inherently unequal. For example, assume that the
+ ' work: ' +this.job '); at } - var p2=new Worker (' Mumu ', ' female ', ' student '); - p2.showname (); -P2.show ();Analyze the following example: Create a person function and create a show and showname function on the person's prototype objectThe worker function is created, the worker prototype object inherits the prototype object of person Worker.
JavaScript does not have the concept of class, but almost everything is object-based, but also to achieve inheritance, which is the biggest difference between JS and other OOP language, which is the most difficult to understand JS. Let me say my personal understanding.First of all, from the creation of the object, there are generally the following methods:1. Create an object instance, and then add propertie
Prototype description: The following describes prototype in the js class:
=====
Constructor attributes
Applied to: Array Object | Boolean Object | Date Object | Function Object | Number Object | String Object
Requirements
Version 2
Returns a reference to an object type prototype.
ObjectName.
JavaScript prototype and prototype chain Ultimate detailed
I. Common objects and Function objects
In JavaScript, everything is the object! But the objects are also different. It is divided into ordinary object and function object, Object,function is the function object with JS. The following examples illustrate
The prototype attribute of the object in JavaScript, which can return the reference of the Object Type prototype. This is a pretty straightforward explanation. To understand it, you must first correctly understand the concepts of object types and prototypes.1. What is prototype?The
Constructors Create objectsFirst we use the constructor to create an object:function Person(){}var person = new Person();person.name = ‘tom‘;console.log(person.name) //tomIn this example, person is a constructor, and we create an instance object person with new.Next, get to the point:PrototypeEach function has a prototype attribute, which is the prototype that we often see in various examples, such as:funct
Constructors Create objectsLet's first use the constructor to create an object:function Person () {} var New = ' name '// nameIn this example, person is a constructor, and we create an instance object person with new.It's easy, then, to get to the point:PrototypeEach function has a prototype attribute, which is the prototype that we often see in various examples, such as:function Person () {} // Although
This article describes in detail the prototype inheritance of JavaScript, which is very detailed. For more information, see JavaScript as an object-oriented language. In JavaScript, there is a classic saying that everything is an object. Since it is object-oriented, it has three main characteristics of object-oriented:
1. in prototype mode 1.1, each function we create has a prototype attribute, which is a pointer pointing to an object, the purpose of this object is to include attributes and methods that can be shared by all instances of a specific type. A simple explanation of the above is: first, we... syntaxHighlighter. all (); 1. in prototype mode 1.1, each function we creat
coupled to an object), there is no reason not to share functions among multiple objects.
Prototype mode, using the prototype property of the constructor to specify the properties and methods that should be shared. When combining constructor and prototype patterns, use constructors to define instance properties, and use prototypes to define shared properties
The Class in Prototype is generally created using the Class. create method, for example, PeriodicalExecuter type. You can call newPeriodicalExecuter (xxx) to generate an object.
The Code is as follows:
/*** A well-designed timing actuator* First, a PeriodicalExecuter type is created by Class. create,* Configure the
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 explanation, Factory mode, constructor mode, prototype
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.