Javascript prototype and prototype chainAs we all know, JavaScript does not contain the traditional class inheritance model, but uses the prototype model. The code implementation is probably like copying the code function Student (name) {this. name = name;} var Kimy = new Student ("Kimy"); Student. prototype. say = fun
After the process of creating the object and the new method is clear, it is much easier to understand the concept of the prototype.The purpose of the prototype exists in order to be more memory-efficient inheritance.I think the main thing in the prototype is to figure out what these 4 concepts are, what the explicit prototypes point to, what the implicit prototypes point to, what the constructor points to,
The prototype attribute can be considered a big difference between JavaScript and other object-oriented languages.In short, prototype is "a method of adding methods to objects of a class," and using the prototype property, you can dynamically add properties and methods to the class to achieve the effect of "inheritance" in JavaScript .The object that is construct
Introduction to prototype in JavaScript, and javascript prototype
Inheritance in JavaScript is completed through prototype chain: each object has another object as its prototype, and the object inherits the property from this prototype ). For each object, you can use the fol
For more information about prototype, see. Var Class = {
Create: function (){
Return function (){
This. initialize. apply (this, arguments );
}
}
}
Defines a class function as a template or prototype for creating a class.
Usage
The Code is as follows:
Test Class. create ()
If you want to convert the dom set obtained through getElementsByTagName to a real array, you may not understand the result (different from what you expected). The test code is as follows: runjs. cncodei517birf wants to convert the dom set obtained through getElementsByTagName into a real array, which is a bit confusing for their results (different from what they expected). The test code is as follows:
Http://runjs.cn/code/i517birf
Reply content:
The test code is as follows:Http://runjs.cn/
Purpose: Use the prototype example to specify the object type, and copy the prototype to create a new object.
Applicability:
When the instantiated class is specified at runtime
To avoid creating a factory class parallel to the product class
When a class can only have one of several combinations of different states
Example:
ExampleCode:
# Pragma once
// Sun Wukong: one change, two changes,
the function name itself is a variable. For function declarations and function expressions as shown below, it is very useful to understand that a function in JavaScript cannot be overloaded without considering the difference between a function declaration and a function expression.1 function f (a) {2 return a + 3} 4 5 function f (a) {6 return a-10; 7} 8 9//without considering the difference between function declaration and function expression, It is equivalent to the following ten var
There is usually no difference between iterating over an array's result in JavaScript, and its loop variable i is an array index starting with 0 (for in if the property collection of a non-array object is traversed, this I is the property name, or the key). Also note that the loop variable i is a string type, traversing the array with for. If you expand the array, then you need to pay attention to some problems when you iterate over the arrays with for.
Test code:
Copy Code code as follow
Let's start with a simple constructor + prototype Object appletfunctioncreateobj (uName,uAge) { this.userName=uName; this.userAge=uAge; }createobj.prototype.showusername =function () { returnthis.username;} CreateObj.prototype.showUserAge=function () { returnthis.userAge; } This program, no problem, but very redundant, each time you expand a method to write a prototype object, we can put the
Let's start with a simple constructor + prototype Object appletfunctioncreateobj (uName,uAge) { this.userName=uName; this.userAge=uAge; }createobj.prototype.showusername =function () { returnthis.username;} CreateObj.prototype.showUserAge=function () { returnthis.userAge; } This program, no problem, but very redundant, each time you expand a method to write a prototype object, we can put the
Love life, enjoy entertainment, focus on technology, welcome to pay attention to Qger, we witness growth together!What is prototype mode?
官方解释: cloning of an existing object instead of creating new one and can also be customized as per the requirement.(克隆一个现有对象来代替新建一个对象,并且可以按定制要求克隆)
Popular explanation: By creating a new prototype object (which implements an abstract class, interfa
The latest version of Prototype (1.5rc2) User Guide (1) before writing this Guide, let's first introduce what Prototype is mainly, you should have heard of this javascript framework before. Prototype is a basic javascript Application Framework. First, we will reference an official website introduction.
Prototype is a
Prototype design practices and prototype practices
In the instructor management system project, start learning and use Axure for prototyping. Although Axure can be used for some simple interface design and interactive design, I still feel that what I have mastered is only a tiny part of Axure's powerful functions.
When talking about prototype Design, you have to
Understand the following diagram to understand JS prototype, prototype chain1, each object has its own prototype object, each object has a prototype property, which is a pointer to the object's prototype object, the prototype obje
This article mainly introduces the object-oriented JS basic explanation, Factory mode, structural function mode, prototype mode, mixed mode, dynamic prototype mode, the need for friends can refer to the nextWhat is object-oriented? Object oriented is an idea! (nonsense).Object-oriented can treat the key modules in the program as objects, while the modules have properties and methods. This way, if we encapsu
JavaScript also has a way of inheriting implementations that use prototype prototypes and their chains in comparison to the inheritance of other compiled languages.1, we first use a simple example to understand the prototype chain,Function Superclass () { this.value = "Super";}SuperClass.prototype.getSuperValue = function () { return this.value;}function Subclass () { this.subclassvalue = "Sub";}Subclass.pr
JS in the prototype is a more difficult to understand the part of JSThis article is based on several knowledge points:1 prototype design patternClone () can be used in. NET to implement the prototype methodThe main idea of the prototype method is that there are now 1 class A, and I want to create a class B, which is a
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.