Discover javascript class vs prototype, include the articles, news, trends, analysis and practical advice about javascript class vs prototype on alibabacloud.com
OverviewFirst, let's briefly describe the concept of inheritance: When a class and another class form the "is a kind of" relationship, these two classes form an inheritance relationship. The two sides of an inheritance relationship are subclasses and base classes, and subclasses can reuse properties and methods in the base class. In the previous article we introd
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
Objective
JavaScript does not contain the traditional class inheritance model, but rather uses the Prototypal prototype model.
Although this is often referred to as the shortcoming of JavaScript, a prototype based inheritance model is more powerful than traditional
First, the concept of the prototype chainJavaScript is an object-oriented programming language in which everythingin JavaScript is an object , and objects are not independent of each other, but have "inherited" relationships.This "inheritance" relationship differs from the inheritance in Java or C #. Java or C # has the concept of a class, subclasses inherit the
This article mainly introduces the prototype Learning Guide in JavaScript, including the important knowledge of prototype chain and prototype inheritance. For more information, see
What is the prototype?
The Function type has a prototyp
attributeUndefinedOrNullThe attribute cannot be deleted.OnlyIs to remove the association between attributes and values.
?
1
VaR OBJ = { Null ; Delete OBJ. Baz; For ( VaR I In OBJ) { If (Obj. hasownproperty (I) { '' + OBJ [I]);
The above output results include:Bar undefinedAndFoo null-OnlyBazDeleted from the output. Property name syntax (notation of keys)
?
1
VaR Test = {'Case':'I am a keyword so I must be notated as a string',
Recently, I have been familiar with html5. Of course, anyone who has been familiar with html5 knows that html5 only provides some new labels. The core of the entire implementation is still in javascript. During the summer vacation, we also launched the ext4 web desktop, which is more about javascript. For javascript, only document. getElementById () and alert ()
JavaScript's archetypal objects are always tangled. Even experienced JavaScript experts and even their authors often give a very limited explanation of the concept. I believe the problem comes from our earliest understanding of the archetype. Prototypes are always closely associated with new, constructor, and confusing prototype attributes. In fact, a prototype i
inheriting classes.JavaScript
12345678910111213141516171819
function father() { This . A = ' father ' }father. Prototype. b = function() { Alert(this. A) }var child = function() { father. Call(this) }child. Prototype = new Father();
New keyword and obeject.create methodIn the article, bloggers point out the drawbacks of usi
Deep understanding of javascript prototype chain and inheritance
Javascript itself is not an object-oriented language, but an object-based language. For those who are used to other OO languages, it is not suitable at first, because there is no "class" concept here, or the "class
This article introduces the static and prototype attributes in javascript, and attaches an example analysis. it is very practical. if you need it, you can refer to it. This article will introduce you to the Javascript static method and prototype method. if you do not know about the
JavaScript-Image Understanding object-oriented, prototype, and inheritance
This is the second overall review of JavaScript's object-oriented and prototype knowledge. This part of knowledge is abstract but very important. It encapsulates the Later class libraries and implements the overall architecture. In this section,
preface JavaScript does not contain the traditional class inheritance model, but rather uses the Prototypal prototype model. Although this is often referred to as a disadvantage of JavaScript, the prototype-based inheritance model is more powerful than traditional
Let's look at an example.function User () {}var u1 = new User (); Console.log (u1.prototype);//Undefined Use object instance cannot access Prototypeconsole.log ( User.prototype);//{}, Access Prototypeconsole.log (u1.__proto__) using the constructor name,//{}, using the object instance to access the prototype pointerThis is the basic difference between __proto__ and prot
The foo variable is the for (var i in foo) { if (Foo.hasownproperty (i)) { console.log (i)) {if (i) }, in the above example;}JavaScript does not contain the traditional class inheritance model, but rather uses the Prototypal prototype model. Although this is often referred to as a disadvantage of JavaScript
We know that adding prototype to JavaScript classes is very easy. The following two methods are commonly used. Are there any differences between the two methods?JScript Class:Copy codeThe Code is as follows:Function JSClass (){}Extends prototype method:Copy codeThe Code is as follows:JSClass. prototype. MethodA = funct
One, what is the prototype property of the object in JavaScript JavaScript, the prototype property of the object that is used to return the reference to the object type prototype. We use the prototype property to provide a set o
Javascript prototype details1. Basic prototype features:Ps: 1. A prototype and a class in other languages, defined attributes, and methods can be shared by all objects produced by this class.2. Modifying the attributes or methods
Due to language design, JavaScript does not have the concept of "class" in the true sense. The new command is usually used to instantiate an object. The essence of this language function depends on the prototype chain pattern unique to JavaScript.
So strictly speaking, JavaScript
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.