When using object-oriented programming, the inheritance between objects is naturally unavoidable! And the prototype is a very important way to achieve JavaScript inheritance!
Let's start by looking at the following code:
Copy Code code as follows:
function person (name, age) {
THIS.name = name;
This.age = age;
}
Person.prototype.getInfo = function () {
Alert ("My name is" +this.name+ ", and I have" +this.age+ "years old");
DOM note (12): Prototype object and dom prototype
Because I have previously paid a note on the prototype object: Let's talk about the prototype mode in JavaScript. Now I can see this topic again and have a better understanding of the prototype. So I have to talk about the
prototype is a more difficult to understand the concept of JavaScript, the prototype related to more properties, the object has "prototype" attribute, the function object has "prototype" attribute, the prototype object has "constructor" attribute.
First, the initial knowled
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 prototype object of object A is B, a
object itself as the first parameter. The difference between the two is the second argument: Apply passes in an array of parameters, which is the combination of multiple parameters into an array, and call is passed in as a call parameter (starting with the second argument).Closure Depth: http://www.cnblogs.com/onepixel/p/5062456.html1 prototype design patternClone () can be used in. NET to implement the prototype
JS prototype chain details and sample code, js prototype sample code
Preface
On segmentfault, you can see the following question:
var F = function(){};Object.prototype.a = function(){};Function.prototype.b = function(){};var f = new F();
Q: Can I obtain a and B from f? What is the principle?
At first glance, it was a bit difficult. I studied it carefully and found that I still did not understand the
Prototype Mode prototypePrototype mode is also a pattern of object creation, and the main purpose is to create new objects by copying existing objects. It has the advantage of not having to use the new one every time you instantiate the object, which can improve the efficiency of the program if the new object is time-consuming.Copy in prototype mode is divided into shallow copy and deep copyShallow copy: Co
Prototype objects are also not without drawbacks. First, it omits the process of passing initialization parameters to the constructor, resulting in all instances getting the same property value by default. While this will somehow bring some inconvenience, it's not the biggest problem with prototype objects. The biggest problem with prototype objects is caused by
Topic comments
This topic belongs to JavaScript more difficult to understand the knowledge point, the knowledge is also very abstract abstruse, belong to the JavaScript object-oriented thinking category, if there is no object-oriented programming thinking students, must be stumped, even if there is some OOP students to answer it is also more laborious , not 1:30 will be able to speak clearly. But the interviewer asked, stating that he is skilled, in a more professional terms to answer the good,
Analyze the php prototype mode and the php prototype. Analyze the php prototype mode and the php prototype mode: Use the prototype instance to specify the object type, and copy the prototype to create a new object. Application sce
Good description from "dead of winter"
The prototype-oriented language idea is exactly the same as the prototype mode: The objects cloned from the same prototype are a class of objects. The prototype-oriented language provides language-level support for this mode, that is, all the definitions of "classes" are implemen
I. IntentionSpecify the type of object to create with a prototype instance, and create a new object by copying the prototypes Second, the prototype pattern structure diagram
Third, the main role in the prototype modelAbstract prototype (Prototype) role: Declares an interf
Class Prototype. js learning Prototype. as a successful open-source framework of javascript, js encapsulates a lot of useful functions. Although the official website does not provide any documentation, a lot of related documents are found on google, however, I still encountered some problems in the process of learning and using it. I hope that some familiar friends can give more advice on
Prototype chain mode1. Each object (the instance is also an object) has a naturally inherent property: __proto__, which points to the prototype of the class that is currently owned (prototype)2, each function (class is also a function) has a naturally inherent property: prototype (
) {2 this. Name =name;3 this. url =url;4 this. Alerturl =alerturl;5 }6 functionAlerturl () {7Console.log ( this. url);8 }9 varBlog =NewBlog ("xiaokeai", "http://www.xiaokeai.com/"), blog2 =NewBlog ("xiaomeinv", "http://www.123.com/");Ten Blog.alerturl (); oneBlog2.alerturl ();We set the Alerturl to a global function, so that the blog and BLOG2 access are all the same function, but the problem comes again, in the global scope to define a real just want to let the blog use the funct
Php design mode prototype and design mode prototype. The prototype of the php design mode is similar to that of the engineering mode. it is used to create objects. Different from the implementation of the engineering model, the prototype mode is to first create a php design mode pr
In development, using some JavaScript frameworks, such as Jquery, Ext-js, Jquery-ui, Easyui, and so on, will often see prototype in some open source code. So what exactly is prototype? What are the applications in OO front-end development? What problems can be solved from the perspective of software engineering? Let's talk about the magic of the prototype keyword
1. How to accurately determine if a variable is an array type2. Write an example of a prototype chain inheritance3. Describe the process of a new object
Knowledge Point #####
constructor function
function Foo (name,age) { this.name=name this.age=age this.class= ' class-1 ' //return this // The default is this line}var f=new foo (' Zhangsan ',//var f1=new foo (' Lisi ', 22)//Create multiple objects
Constructors-
Before I was in the prototype chain of JavaScript, prototype inheritance and identifier lookup were somewhat confusing,
For example, the following code:
Copy Code code as follows:
function Foo () {};
var foo = new Foo ();
Foo.prototype.label = "Laruence";
alert (Foo.label); Output:laruence
alert (Foo.label);//output:undefined
Today we see the following figure:
Javascrip
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's first look at the common object-oriented language we are familiar. Among the 23 design patterns, you will surely remember that there
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.