Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object.
The code is as follows:
/*** Prototype** Use a prototype instance to specify the object type and copy the prototype to create a new object.**/Abst
The prototype pattern is one of the creation patterns, which is characterized by the "copying" of an existing instance to return a new instance, rather than a new instance. The copied instance is what we call the "prototype", which is customizable.Prototype patterns are used to create complex or time-consuming instances, because, in this case, copying an existing instance makes the program run more efficien
Structure
Intention
Use the prototype instance to specify the kind of object to create and create a new object by copying the prototypes.
Applicability
When the class to instantiate is specified at run time, for example, by dynamic loading;
To avoid creating a factory class hierarchy that is parallel to the product class hierarchy;
When an instance of a class can have only one
Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object.
Copy codeThe code is as follows:
/**
* Prototype
*
* Use a prototype instance to specify the object type and copy the prototype to create a new obj
When I first came into contact with this prototype I refused, I still spent a part of my time understanding this thing, not proficient, what questions to reply to belowAfter all, I was used to the bricks (funny);As I understand it, prototype is nothing more than a function of two foundations:1. Dynamically adding properties and methods of a class2. Copying the contents of the original classLet's take a look
Four. __proto__JS when creating an object (whether it is a normal object or a function object), there is a __proto__ built-in property called, which points to the prototype object that created its constructor.The object Person1 has a __proto__ property, and the constructor that creates it is person, and the prototype object of the constructor is Person.prototype, so:person1.__proto__ == Person.prototypePlea
===========================================
Objective
===========================================
Recently like MooTools (encounter AH), in the public expressed his preference. Many friends ask me why I want to love each other, in fact, the reason is quite a lot.
Here today I intend to enumerate some of them. Let more friends to understand MooTools, also hope to have more friends like him. The title of the article is doomed I will tell more about MooTools than
If you want to understand the internal relationship between function and object, you must introduce another two concepts dominant prototype and stealth [[prototype]] Concepts1. Prototype: Each function object has a display prototype property that represents the prototype of
Although the prototype pattern is a pattern of creation, it has nothing to do with the engineering model, and the idea of the pattern is to copy and clone an object as a prototype, and create a new object similar to the original object. This summary will be explained by the copy of the object. In Java, the Copy object is implemented through clone (), and a prototype
Design
Java Design Pattern---prototype (prototype) mode
Definition: Specifies the type of object to create with a prototype instance, and creates a new object by copying the prototypes. The prototype mode allows one object to create another customizable object without having to know any details of how it was created,
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
JavaScript prototypes:Each object initializes a property within it, which is prototype (prototype).Prototype chain:When we access the properties of an object, if the object does not exist inside this property, then he will go to prototype to find this attribute, this prototype
When I read a blog post, I tested the prototype chain of JavaScript, the prototype object, and found that each constructor (assigned to a prototype ) New object has its own independent prototype object __proto__.Prototype and __proto__ point to the same object, one is "class
...At this time, can you put these public methods in one place?Great prototype appear, each function has a prototype attribute, which is actually a pointer, always point to an objectWhat is the purpose of this object? ---to include specific properties and methods, and act as a share of all instances functionRen () {}varobj=Ren.prototype; //alert (obj.constructor);Obj.name= ' Wednesday '; Obj.age=20; OBJ.F
1. Prototypesprototype Design pattern the so-called prototype design pattern, in fact, is the object copy, this feature in all languages are basically exist.We know that in OC, Object assignment is actually a reference copy of an object, which is actually equivalent to a pointer in C language. A new variable was created, but it still points to the same piece of memory address.So once a reference changes the properties of the object, all references to
To understand the prototype mode, you must first understand the shortest replication and deep replication in Java. In some cases, replication is also called cloning. Java provides these two cloning methods.
Shortest: all the variables of the cloned object contain the same value as the original object, and all its references to other objects still point to the original object. In other words, the shortest clone only clones the objects to be considered
Understanding javascript prototype and scope series (12) -- Introduction [Scope], javascript prototype
For the articles in the previous sections, refer to understanding the javascript prototype and scope series.
When it comes to scope, you may be familiar with one sentence (with js development experience): "javascript has no block-level scope ". The so-called "Bl
Each object has a prototype, but not all objects have the prototype attribute. In fact, this attribute is only available to function objects.Var a = function (){};Var B = [1, 2, 3];A. prototype; // function (){}B. prototype; // undefined
The constructor itself is also an object and has its own
Prototype
As you all know, JavaScript does not contain the traditional class inheritance model, but instead uses the prototype prototype model. The code implementation is probably like this
function Student (name) {
this.name = name;
}
var kimy = new Student ("KimY");
Student.prototype.say = function () {
Console.log (this.name + "say");
}
Kimy.sa
one. Defines the type of object created with the prototype instance, and creates a new object by copying the prototypes.
Two. Structure
three. Participants
Prototype: Cloning its own interfaces (such as Fruitprototype in code implementations)
Prototypetool: Managing prototype's tool classes, storing prototypes to replicate themselves to data interfaces (such as Fruittool)
Concreteprototype: Implementin
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.