Discover javascript class vs prototype, include the articles, news, trends, analysis and practical advice about javascript class vs prototype on alibabacloud.com
Basic understandingJavaScript objects can be divided into two categories:
ordinary objects, except for objects other than the function object, are instances of the new function object () , the normal object is not prototype, and there is no inheritance and the prototype chain is said.
function Objects , including two kinds:
Functions created by Function: function f1() { } /
Prototype: JavaScript reference type
What is prototype?
The prototype attribute in the Javascript Object can return the prototype reference of the object type, and the prototype belong
Copy Code code as follows:
/* Based on Alex Arnell ' s inheritance implementation. */
var Class = (function () {
Temporarily store Parent's prototype
function subclass () {};
Ways to create a class
function Create () {
var parent = null, properties = $A (arguments);
Check whether a parent object is specified when a new
Inheritance is one of the most-talked-about concepts in oo language, and it is also a difficult concept for beginners who touch JavaScript first. There are two main types of inheritance: One is interface inheritance, the other is implementation inheritance. In ECMAScript, we only support implementation of inheritance, so let's talk about implementing inheritance today. Implementation of inheritance is to inherit the actual method, mainly rely on the
CopyCode The Code is as follows: // var people = {name: "Xiong", age: 15 };
// Var person = function (user, age ){
// This. Name = user;
// This. Age = age;
// This. Say = function () {alert ("I am" + this. Name + "\ n" + this. Age );}
//}
// Var Chairman = function (name, salary ){
// Person. Call (this, name );
//}
// Var bill = new person ("bill", 15 );
// Var Hu = new chairman ("Hu Jintao ");
// Person. Prototype. Eat = function (){
// Alert ("I'm
Because JS Foundation has been very poor, so I feel a lot of basic knowledge is not reliable, now take a moment to understand, although the completion of this post I may still not know, but the record at least I will again and again, and deepen the impression or get a different understanding of the present.What is inheritance?Often a lot of code after you have completed the construction, but also need to construct another similar function function; A lot of such examples are: vehicles/cars, Pers
To find out the prototype chain is to understand the function type first, in JavaScript there is no class concept, are functions, so it is a functional programming language. A class has an important feature, which is that it can create an object that is a template based on its constructor. In
"Object-oriented" has three basic characteristics, namely encapsulation, inheritance and polymorphism. Generally speaking, three features are fully satisfied, we call it "object-oriented language", while the language that satisfies some features is "object-based language".The inheritance characteristics of the "object System", there are three implementations, including class-based, prototype-based, and base
operator to compare them.
console.log(Dog.prototype.constructor === Dog);//trueWe can see that the two results are actually equal.
So, can we use constructor to access and ask about prototype? Yes, this is all right. In this way, it is equivalent to forming a circular pointing link. In fact, this can also be verified by recursion, stack Overflow will soon be called when calling recursion, because there is no exit in this recursive call.
The
This article mainly introduces how to use Object in JavaScript. prototype. toString determines whether it is an array. This article describes the Object. prototype. toString related knowledge, and provides the implementation code to judge the array. using this method, you can also determine other data types of javascrpty. if you need it, you can refer to why Obje
Understanding javascript prototype and closure (16)-conclusion and understanding javascript
I used a total of 15 articles to prototype and closure javascript.
First, javascript is "not easy to learn ". It is not how difficult it i
accessible to the Attr property of the parent class.But at this point, all instance objects of the Super class share the Attr property, and the change of one instance to the Attr property causes the change of the property value attr the other instance object, which should be avoidedfunction Super () {}super.prototype.attr= ' a '; Super.prototype.func=function() {alert (' Super ');}; function Sub () { this. x= ' 1'=super.prototype; Sub.prototype.te
All content of this blog is used by Creative Commons Licenses license. When quoting this content, please retain W, source, and non-commercial .Click RSS to subscribe. (Google Reader is recommended, if your browser does not support direct subscription, please add it directly in Google Reader.)SummaryThis series of blogs focuses on some of the advanced applications that are often confusing in javascript usage, including:
This article mainly introduces prototype in JavaScript. This article describes three methods for accessing prototype objects and how to determine whether there is a prototype link between two objects, if you need a prototype chain, you can refer to the inheritance in
This article mainly introduces prototype in JavaScript. This article describes three methods for accessing prototype objects and how to determine whether there is a prototype link between two objects, if you need a prototype chain, you can refer to the inheritance in
: "oseye.net", getinfo:function () { return this.url; } }; Console.log (Website.getinfo ());
Prototype (prototype) mode Each JavaScript object has a Prototype property, and you can add methods dynamically to the class using the
Differences between the two implementations of JS class definition prototype methods many of us know that it is very easy to add prototype methods to JavaScript classes. The following two methods are commonly used. Are there any differences between the two methods?
JScript Class
reference to the person superclass, so you have to assign a new value to yourself Console.log (Programmer.prototype.constructor);
/*function person (name) {this.name = name;} */Programmer.prototype.constructor = programmer;
Console.log (Programmer.prototype.constructor);
/*function programmer (name, sex) {Person.call (this, name); this.sex = sex;} The//subclass itself adds the Getsex method Programmer.prototype.getSex = function () {return this.sex}//Instantiate this subclass var _m = new Pro
To understand the prototype chain, you must first understand the function type. In javascript, all classes are functions, so it is a functional programming language. A very important feature of a class is that it can create an object with it as a template based on its constructor. In javascript, functions have two func
Let's talk about 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 prototype inheritance method, use the prototype Attributes provided by Alibaba Cloud to
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.