The question to be resolved: Can we reduce the use of new, while avoiding the need for new objects, to understand the object's class name.
Train of thought: PHP5 provides a cloning method, we can add an object, and then each need to add and her similar objects, cloning he can be.
Prototype (Prototype) Pattern Example:
The code is as follows
Copy Code
Machine Soldier Class Cla
I. Object: Normal Object Function objectTwo. Constructor features: 1. A new instantiation is required, and the This object is used internally to point to the instance object 2 that is about to be generated. Uppercase letters, used to distinguish common functionsfunction Person (name) { the name=name}var person1=New person (' Xiaohong ') )var person2=New person (' Lili ')Person1.constructor=person constructor points to constructors, person's built-in properties Person.prototype (function objec
The intent of the prototype model is:
By giving a prototype object to indicate the type of object you want to create, you can then create more objects of the same type with the method of copying the prototype object.
This pattern has been implemented in the Java class Library, so long as you define a class that implements the Cloneable interface, objects create
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,
On the internet to find a lot of this model of information said is not thorough, looked at half a day is foggy. Had to study one by oneself.Prototype mode is a creation design pattern that returns a new instance by copying an existing instance, rather than creating a new instance. The copied instance is what we call a prototype, which is customizable.Prototype patterns are used to create complex or time-consuming instances, because in this case, copyi
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
Design Pattern Five: Introduction to prototype mode (PROTOTYPE)
The prototype pattern is one of the creation patterns that creates new objects by copying the prototype objects.
The universal Java Superclass object provides a clone () method to implement a copy of the object.
You can use the
Prototype and prototype in JavaScript
1. prototype
There is no class concept in JavaScript, but JavaScript can indeed implement overload, polymorphism, and inheritance. In fact, these methods can be explained by reference in JavaScript and prototype in combination with the variable scope.2. Simple Example
Var Blog =
I. What is a prototype?A prototype is an object that other objects can use to implement property inheritance.Simply put, any object can be a prototype.Prototype properties: Each function we create has a prototype property, which is a pointer to an object that contains properties and methods that can be shared by all instances of a particular type. This object is
First of all, the reference blog, thankHttp://blog.sina.com.cn/s/blog_6c62f4330102wq0u.htmlhttp://blog.csdn.net/leadn/article/details/51781539And so on, and there are some other links that don't stick here.JS in about prototype article many, today himself write a bit of their own understandingDo not like to come up on the sticky concept, because if the concept can understand, also do not need to write this article.about 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.