Understanding the prototype chain in JS, the relationship between prototype and __proto__Speaking of prototype, we have to say the new process first.Let's look at this piece of code first:
1
A very simple piece of code, let's see what this new has done? We can split the new process into the following three steps:The key is the sec
In JavaScript, the function itself is also an object that contains methods and properties.Length returns the number of arguments.In the 4th chapter, we have learned how to define a constructor function and use it to create a new (constructed) object. The main intent of this approach is to invoke the function with the new operator to achieve the purpose of accessing the object's this value, and then the constructor can return the object it created to us. In this way, we have a way to give new obj
We know that a prototype is an object that other objects can use to implement property inheritance, in addition to prototype, and __proto__1. The difference between prototype and __proto__Prototype is a function -only attribute __proto__ is a property of each objectBut __proto__ is not a canonical attribute, only part of the browserThis property is implemented an
Doubts come from:
Copy Code code as follows:
function Foo {
this.name = ' Foo ';
}
Alert (Foo.prototype = = Function.prototype); False I was wondering why Foo's prototype was not function.prototype.
The following example lets me take it for granted that O.prototype = = Function.prototype should be true:
Copy Code code as follows:
function foo () {
this.name = ' Foo ';
}
Function.prototype.sayHello =
node behind the element.Siblings: function (element ):Returns all sibling nodes of the element.Match: function (element, selector ):Use the match method of Selector to match the elements (Selector will be introduced later). The selector parameter is a css selector expression or a Selector instance in Prototype. If the element matches the selector, true is returned, otherwise, false is returned. For example, for a p whose className is logcss, the foll
Copy CodeThe code is as follows:
/*** Prototype mode** Use the prototype instance to specify the kind of object to create. and create new objects by copying this prototype**/Abstract class Prototype{Private $_id = null;Public function __construct ($id){$this->_id = $id;}Public Function GetID (){return $this->_id;}
Analysis of JS prototype inheritance and class inheritance, analysis of js prototype inheritance
Let's first look at the inheritance of JS classes.
Let's look at the JS prototype inheritance.
We can test that the inheritance of the JS class children. constructor = father returns true, while the prototype inherits chi
Defined in Gof:"Uses a prototype object to produce an object of the specified class, so when the object is produced, it is done using the Copy prototype object." ”In UnityDevelopers can assemble game objectsIt can include complex componentsOnce assembled, you can store it as a prefab type of unity asset resourceInstantiation methods used in program code (gameobject.instance)Is the application of a
Often interviewing at the front or communicating with other peers is the best way to use a prototype when it comes to constructing a constructor in JS: Defining a method on the prototype of a constructor method, the benefit is that the instance that is generated by the constructor has a method that points to the index of a function. This will save memory.Of course, there is no problem with this statement, b
Every object in JavaScript has a prototype property.Object methods, class methods, prototype methods1, Object method: Understanding is very simple, mainly if the class generates an instance, then the instance can use this method2. Class method: A method that does not need to be used to generate an instance3, the prototype method: mainly used to expand the JS exis
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD">HTML> Head> Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> title>Untitled Documenttitle> Scripttype=text/javascriptCharSet=utf-8> //Customizing the prototype object alters the constructor of the prototype object. //Concept of Prototypes: All properties and meth
First, describeThe prototype pattern is a prototype object that identifies the type of object to be created, and then copies the creation of more homogeneous objects using the method of copying the prototype object. For example, we have an object in the dynamic process of the program, which contains a series of valid data, we need a new object that is exactly the
In "JavaScript Play Inheritance (ii)", I used the prototype inheritance method to implement JavaScript inheritance, and the prototype is what the mystery. In this article, I will focus on the prototype to start the discussion.
Aside from JavaScript, let's look at the familiar common object-oriented language. In 23 design patterns, you will remember that there is
This article mainly introduces the jQuery prototype attributes constructor, selector, length, jquery and prototype Methods size, get, toArray, which are very detailed. If you need them, you can refer to them. First, let's take a look at the prototype attributes and methods defined in jQuery1.7.1?
The first is the constructor attribute.
I believe developers who
Var Class = {
Create: function (){
Return function (){
This. initialize. apply (this, arguments );
}
}
};
Object. extend = function (destination, source ){
For (var property in source) destination [property] = source [property];
Return destination;
};
Function. prototype. bind = function (object ){
Var _ method = this;
Return function (){
// Replace this in _ method with the object and call the _ method
Return _ method. apply (object, arguments );
}
}
To better understand this article, please learn the basic knowledge of prototype and prototype chain in advance.
Let's take a look at the following questions about the pitfalls:
1 Object.__proto__ == Object.prototype2 Function.__proto__ == Function.prototype3 Object instanceof Function4 Function instanceof Object
A lot of people may be confused at first glance (including the author). It feels a bit like an
Read the study notes in Chapter 2nd of JavaScript advanced programming (version 6th. The prototype has a problem in the reference type:
Function supertype () {} supertype. prototype. color = ['red', 'Blue ', 'green']; var instance1 = new supertype (); instance1.color. push ('black'); var instance2 = new supertype (); console. log (instance2.color );
The prototype
// When there are many attributes and methods, writing is not very convenient. You can write them in json format.// Because the prototype is not specified through Person. prototype, the constructor will not point to Person but to Object.// If constructor is really important, you can describe the prototype in json.Function Person (){}
Person.
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
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.