Prototype Mode description
Description: Use a prototype instance to copy the creation of a new customizable object, a new object that does not need to know the exact process of the original object creation;
Process: Prototype => new Protoexam => clone to New Object;
Use related code:
Copy Code code as follows:
function
First, prototype (Prototype) mode
The purpose of the prototype pattern is to specify the type of object to be created by giving a prototype object, and then create more objects of the same type with the method of copying the prototype object.
From the means of Sun Dasan
T
Introduction of prototype Model (Brief Introduction)
Prototype mode (Prototype pattern): Specifies the type of object to create with a prototype instance, and creates a new object by copying the prototypes.
Specify the kind of objects to create using a prototypical instance, and create new objects by copying this
1. Prototype rulesA. All reference types (arrays, objects, functions) have object attributes and are free to extend properties;var arr = [];ARR.A = 1;B. All reference types (arrays, objects, functions) have a _proto_ attribute (implicit prototype), and the property value is an ordinary object;C. All functions have a prototype (explicit
Overwrite prototype
Prisoner example//1. Defines the prototype object var proto = {Sentence:4,//imprisonment years Probation:2//probation years};
2. Define the constructor of the prototype object var prisoner = function (name, id) {this.name = name;
This.id = ID;
};
3. Associating the constructor with the prototy
The concept of prototype in JavaScript aptly reflects the meaning of the word, and we cannot interpret it as a prototype concept of C + +.
All of the function-type objects of JavaScript have a prototype attribute. The prototype property itself is an object type, so we can also add arbitrary properties and methods to th
Let's talk about javascript prototype inheritance and 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 impleme
For the new, JavaScript prototype is a very annoying thing, one prototype easy to confuse with __proto__, and the various points between them is really a bit complicated, in fact, there have been a lot of articles on the market to try to say clearly, there is a so-called very classic diagram, The above painted a variety of lines, one will connect this one will connect that, to tell the truth I see very dizz
In-depth analysis on prototype of ctictipt:Is prototype attributes a copy, a reference, or a fixed search method?
//
What is the prototype principle of javasctipt? When an instance is created, it copies the prototype, obtains a copy of the prototype attribute, or enables th
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,
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
/* Source author: stone not Easy (Louisshi) contact information: http://www.shibuyi.net============================================= ====================================================== Program name:javascript Package Library Prototype version Iteration : non-functional total:14 features:1. implementation code concatenating 2.id/name/tagname/ class node Get 3.class selector Add with remove 4.css rule Add and remove 5. set with Get element inner text
The prototype property can add properties and methods to any object (number, Boolean, String, date, and so on).
Note: The prototype (PROTOTYPE) is a global property that can be used in almost all objects.Grammar
Object.prototype.name = value
Instance:
Here's an example of how to use the properties of a protot
a great extension of JavaScript and a good support for Ajax, as well as a library of effects based on such libraries at home and abroad. Prototype.js is not only a great practical value of the JS library, but also has a high learning value. --in Prototype.js, prototype object is an important mechanism to realize object-oriented. Each function is an object (function) that has a child object prototype ob
Copy code code as follows:
/**
* Prototype Mode
*
* Use a prototype instance to specify the kind of object to create. And by copying this prototype to create a new pair of Like
*
*/
Abstract class Prototype
{
Private $_id = null;
Public Function __construct ($id)
{
In JavaScript, this is defined when created. What does this sentence mean?
function Foo () {
this.name = ' Peter ';
}
Foo ();
Console.log (name);//this is the global object when it is created, so the name here is Peter;
So what's different about adding a keyword new?
Let's say varobj = new Foo ();
In JavaScript, the new keyword does three things:
First, generate a new object
One, Varo = {}; Generate an Empty object o
Second, o.__proto__= foo.prototype;//the
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.