Discover javascript constructor function, include the articles, news, trends, analysis and practical advice about javascript constructor function on alibabacloud.com
From: http://maycode.com
Tip: I briefly introduced JavaScript Functions, new, constructor behavior, and prototye basic knowledge. If you have any bias, please point out that it is only for your personal understanding.
========================================================== ========================================================== ======================================I. Several concepts related to
Constructor: constructor of an object. It is a function.
Prototype: the prototype of the constructor. Only functions have this attribute.
Isprototypeof: If object a exists in the original model chain of object OBJ, A. isprototypeof (OBJ) returns true, and OBJ must inherit the attributes of.
_ PROTO __: the protot
JavaScript is a prototype-based object-oriented language. That is to say, each instance object has a prototype. The object inherits attributes and methods from the prototype. This article describes the inheritance of constructor. Speaking of the basic mechanism of JavaScript prototype inheritance, this article details the inheritance of constructors.
From a simp
The syntax of JS is very flexible. There are several different methods for creating simple objects. These too flexible places are sometimes confusing. Let's take a look at several common methods for creating objects in JS today. In the previous article, we introduced the javascript object-oriented basics, this article continues to learn about javascript object-oriented in depth. JS syntax is very flexible,
this in the function to foo. boo. apply (window); // This is window.
2. What is prototype)
1. prototype is essentially a JavaScript Object;
2. Each function has a default prototype attribute;
3. With prototype, we can extend the built-in JavaScript objects.
If this f
by default when we use the JS system or the object we create. any object has a constructor property, inherits from the prototype, andconstructor points to the constructor or constructor that constructs the object. Constructor can be rewritten, so use caution. By default, all prototype objects automatically contain a
Perhaps many beginners in C + + know what a constructor is, but they are unfamiliar with the copy constructor (copy constructor). For me, there's not much chance of using a copy constructor when writing code, but that doesn't mean that the copy constructor is useless, but th
We all say that JavaScript properties are many, can not remember, various structures are difficult to understand. Indeed JS is a quick way to improve the difficult language, but there are other ways to assist the memory. The following is to discuss the JS of a major difficulty-object layout, exactly how the person who designed JS this language was how to do? What did you become when you finished the design?Let's look at a picture:I believe you are not
efficient and less likely to make mistakes.
Here we use an example to explain:
The first approach is to assign values to the data members of the subclass object in the constructor of the subclass.
Code 1:
#include
#include
using namespace Std;
Class Father
{
Public
Father ()
{
cout
}
~father ()
{
cout
}
void print ()
{
cout
}
Protected
String name;
int height;
};
Class Son:public Father
{
Public
Son (String A,int i,int J)//The first argument assign
Function Definition
A function is declared in this way: the keyword function, function name, a set of parameters, and the code to be executed in parentheses.
There are three types of function constructor Syntax:
Js Code
The Code i
A good explanation of JavaScript inheritance, but slow to explain now. Don't say much nonsense, go straight to the chase.Since you want to understand the inheritance, prove that you have a certain understanding of JavaScript object-oriented, such as what is not understood can refer to the "Object-oriented JS basic explanation, Factory mode, constructor mode, prot
example:Copy codeCode: foo (){(=== Window ){Console. log ();}}Foo. boo = (){(=== Foo ){Console. log ();} (=== Window ){Console. log ();}};Foo ();Foo. boo ();Foo. boo. apply (window );
Prototype Prototype is essentially a JavaScript Object. Each function has a default prototype attribute.If this function is used to create a custom object, we call it a
represented by class, but by function, this type of information itself is an object. It is difficult to understand the definition of types and objects in Java,
For example, Javascript defines a Function-type object as follows:
function Cat(){ return 1;};
In this Code, Cat plays two roles: Custom Cat, object Cat,
(separate understanding will be more clear).In short, I think (in my JavaScript position for a few days) that Foo.prototype is the __proto__ "Dad" or "true" of the new instance, and foo.__proto__ is the "shadow" or "View" of the class. (special), when the father changed the son of course different, but the son change is the father will also change (I can only understand, I really don't know). And constructor
Function ("x", "Y", "return X*y");
The actual effect of this line is equivalent to the following line of code.
var f=function (x,y) {x*y};
The function () constructor can pass in any number of string arguments, the text represented by the last argument is a body of functions, it can contain any
We know that by default, an object can be constructed by using new in front of a function. Each object has a constructor attribute, which points to the function that constructs the object. For example, debugging in Chrome is as follows:Program, Clearly shows this:
However, it is not that simple. Let's look at the followingCode:
Obviously, the
Function Definition
A function is declared in this way: the keyword function, function name, a set of parameters, and the code to be executed in parentheses.
There are three types of function constructor Syntax:
Js Code
Copy code
One, what is a virtual function?Simply put, those member functions that are modified by the virtual keyword are virtual functions. The function of virtual function, the use of professional terminology to explain is to achieve polymorphism (polymorphism), polymorphism is the interface and implementation of the separation, with the image of the language is to achie
A good explanation of JavaScript inheritance, but slow to explain now. Don't say much nonsense, go straight to the chase.Since you want to understand the inheritance, prove that you have a certain understanding of JavaScript object-oriented, such as what is not understood can refer to the "Object-oriented JS basic explanation, Factory mode, constructor mode, prot
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.