Functionfoo () {this.value=42;} Foo.prototype={method:function () {}};functionbar () { }// sets the prototype property of bar to the instance object of Foo Bar.prototype=newfoo (); bar.prototype.foo= ' Helloworld ';// Fix Bar.prototype.constructor for Bar itself bar.prototype.constructor=bar;vartest=new Bar () // Create a new instance of bar// example of instance]bar.prototype[foo of the prototype chain Tes
Js prototype, prototype
Var Person = function (name) {// defines a class PersonThis. name = name;}
Var p1 = new Person ("tom ");// Alert (p1.name ); // Adds a show function to the object p1.// P1.show = function (){// Alert (this. name );//} P1.show ();
Var p2 = new Person ("fox ");// Alert (p2.name ); P2.show (); // The show method cannot be called.
//
borrowed to subtly avoid calling new mother (), and then returning the prototype to an O object instance, thus completing the prototype chain setup. Very round, right, that is because we can not directly set Person.prototype = Mother.prototype AH.SummaryHaving said so much, there is only one core: attribute sharing and independent control, when your object instances require independent attributes, all of w
Prototype and closure are the difficulties of Js language. This article mainly describes the inheritance of prototype and prototype implementation. In (2), I will talk about closure and hope to help you. If you have any questions or errors, you are welcome to correct and discuss them.
I.
borrowed to subtly avoid calling new mother (), and then returning the prototype to an O object instance, thus completing the prototype chain setup. Very round, right, that is because we can not directly set Person.prototype = Mother.prototype AH.SummaryHaving said so much, there is only one core: attribute sharing and independent control, when your object instances require independent attributes, all of w
have been disconnected, this time mother how to change has not affected person. * P4: ' Tony '; __proto__: {country: ' USA ', City: ' Washington '} */person.prototype = new mother (); Bind var P5 again = new person (' Luffy ');//This time if you need to apply these changes, it is necessary to re-bind the person's prototype to the mother//P5: ' Luffy '; __proto__: 2, [' Run ', ' Walk ']p1.__proto__.__proto__.__proto__.__proto__//null, you say the end
Summary of common JS creation methods (factory, constructor, prototype, and union) and js Summary
This example describes common methods for creating classes in JavaScript. We will share this with you for your reference. The details are as follows:
Javascript is an object-based language. Almost everything you encounter is an object. However, it is not a real Objec
I read "talking about JS object-oriented programming" a few days ago. At that time, I asked haoshen to findArticleIn some cases, it may be misleading (or different from ECMA). Later I flipped through ECMA and finally found the "standard ......This article is suitable for beginners, especially those who are vague about the constructor, prototype, and prototype cha
Js deep learning-differences between js prototype constructor attributes-jsconstructor
In many js plug-ins, these two attributes are frequently used. I also used them when I write plug-ins myself. I know how to use them, but I don't know the specific differences. I have studied them today,
Constructor returns the const
Before entering the main body, I must first say that I know the prototype of JS this thing twists the process.
Baidu JS prototype article, first look, W3school about prototype introduction:
Do you think this concept is suitable for the definition of
to the newly created object and returns the this by default, that is, does not need to write the return this at the last point.The prototype chain for the newly created Xiaoming is:NullIn other words, Xiaoming's prototype points to the prototype of the function student. If you create Xiaohong and Xiaojun again, the prototypes of these objects are the same as the
(addition){this.salary=this.salary+addition;}
We can create objects as usual:
Code:
VaR boss1 = new employee ("Joan", 200000); var boss2 = new employee ("Kim", 100000); var boss3 = new employee ("Sam", 150000 ); // verify it: // code: Alert (boss1.getsalary (); // output 200000 alert (boss2.getsalary (); // output 100000 alert (boss3.getsalary ()); // output 150000
Here is an illustration to illustrate how prototype works. Every instance of this obj
directly. prototype. toString (), but uses call () to wrap it around. See 2 for details.
2) Object. prototype. toString ()
What is Object ?, Script56.chm (Official M $ tutorial): Obect provides common functions for all JScript objects. In fact, objects are the ancestor of all js objects and are a concept, all objects
Question: What is a prototype in JS prototypeEveryone learning JS have their own explanations, a lot of online interpretation and application, but read their explanations to say or do not understand how to do? (because they say it's too much)Official manual explanation: The Prototype property gives you the ability to a
1, the difference between prototype and __proto__
Prototype is the property of a function,
In JS, when an object calls a method, it first searches itself for whether the method, if not, is found on the prototype chain, which is the _proto_ attribute of the instance object.
For instance person, there is a
========================================================================In the learning of JS object-oriented process, has been constructor and prototype feel very confused, read some blogs and books, feel oneself to understand, now record as follows:We all know that in JS there is a function of things. Generally people call it function. For example, the followin
I. Prototype And ConstructorAll functions of Js have a prototype attribute, which references an object (prototype. This function includes constructor and common function. We are talking about the prototype of the constructor, but we cannot deny that common functions also hav
Js deep learning-differences between js prototype constructor attributes
In many js plug-ins, these two attributes are frequently used. I also used them when I write plug-ins myself. I know how to use them, but I don't know the specific differences. I have studied them today,
Constructor returns the constructor of an o
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.