Discover object prototype hasownproperty call, include the articles, news, trends, analysis and practical advice about object prototype hasownproperty call on alibabacloud.com
One, the object inheritance in JS
There are three ways of inheriting in JS
1.js Prototype (prototype) Implementation inheritance
Copy Code code as follows:
2. Constructor implementation inheritance
Copy Code code as follows:
3.call, apply to implement inheritance
Copy Code code a
This article describes the prototype attribute in JavaScript. This attribute is an important basis for understanding JavaScript classes and inheritance. We have used prototype property simulation class and inheritance implementation in Chapter 1. The prototype attribute is essentially a JavaScript Object. Each function
) {
This.x=x;
}
function B (x,y) {
This.tmpobj=a;
This.tmpobj (x);
Delete this.tmpobj;
This.y=y;
}
Lines 5th, 6, 7: Create temporary properties Tmpobj reference constructor A, then execute inside B, and then delete after execution. When the this.x=x is executed inside B (this is the object of B), B of course has the X attribute, of course B's X attribute and A's X attribute are independent, so they are not strictly inherited.
mother her mother has not ... This is the upward search of the prototype chain.10) You will inherit your mother's appearance, but you can also dye the hair to wash and cut, that is, the properties of the object can be customized, overwriting inherited properties.11) Although you have washed and dyed yellow hair, but you can not change your mother's appearance, your mother's brother and sister with your yel
Label: style blog HTTP Io color ar OS Java Array. Prototype. Slice. Call (document. queryselectorall ('A'), 0) is used to convert a DOM nodelist into an array. The slice () method can extract a part of a string and return the extracted part with a new string. The syntax is arr. Slice ([begin [, end]), where arr can be string or array. For more information, see MDN. Document. queryselectorall ('A') gets a
, and call the methods in the constructor.The above method does not seem to be inappropriate, but we can find that the sayWhat method in the constructor called in the two instances is not the same Function instance:
console.log(gf1.sayWhat == gf2.sayWhat); //false
It is a waste of resources to call the same method but declare different instances. We can optimize the sayWhat function and put it out of the co
() constructor to construct a function-type object (that is, base. What Will JS do during the creation process?
1. First of all, an object will be created and the base points to this object. Typeof this object = "function" 2. Attach the _ PROTO _ attribute to the base so that it is equal to the
Constructor (also predefined ). This is an important and regular step.(Rule: When you execute anything similar to varx = new X (), the prototype of X is assigned to _ proto _ of x __In other words, x. _ proto _ and X. prototype point to the same object.
3. Create a call attribute for the Base, which is a function
Array. Prototype. Slice. Call (thisarg [, arg1 [, arg2 [,...])Member introduction:
ArrayArray object
Prototype[Property]Is the property of an object in Javascript. It is used to return the prototype reference of the
This article by larrylgq prepared, reproduced please note the Source: http://blog.csdn.net/larrylgq/article/details/7395261
Author: Lu guiqiang
Email: larry.lv.word@gmail.com
There are two methods to manage objects in many languages:
I. Prototype
That is, a copy of the original object is used as the new object. The languages used include JavaScript and Ruby
is returned. It sounds a bit difficult, but the logic is simple: Let OBJ "inherit" object! Well, we have seen inheritance, but you will certainly ask, for the first time, we heard that inheritance is about class inheritance. Yes, I do not see the real class inheritance yet, but it is close at hand: Isn't there a prototype for a class, and prototype is an
In general, the JS language is the façade to the object programming language, the concept of objects almost throughout the whole JS learning.Object Two ways to create objects: (to generate an object instance you must call the constructor)1. var obj = {name: "Jer", age:12}; (The preset object () constructor is called in
1.Object class
In JS, object is the base class for all classes, and you can use the object class to create custom objects without having to define constructors (Constructor,prototype,hasownproperty)
var per = new Object (
In JS, call,apply and prototype can implement object inheritance, let's look at an example: functionFatherObj1 () { This. SayHello = "I am Join"; This. Show =function() {alert ("I am FatherObj1"); }; This. GetAll =function () { if(arguments) alert ("GetAll:" + arguments[0]); } } functionFatherObj2 () { This. Sayhi = "I a
arguments to simpleapplydemo () as a set of 55555555 parameters in handlespa ('20140901') as arguments (arguments stands for its own parameters, here only 5555555, that is, Sim = arguments = 55555 */
Alert (this. sim_name );}
Handlespa ('20140901 ');
The call method in msdn calls a method of an object and replaces the current object with another
all objects, we do not need to care about the details of cloning, because it is responsible for the internal implementation of the engine. All we need to do is to explicitly call var obj1 = {}; or var obj2 = new Object (), the engine internally clones an object from "Object.prototype" as a prototype of the new object.
instance and the constructor, the instance is connected to the constructor by constructor. knowing what prototype is and how it came, it's much easier for us to look at the prototype chain of JavaScript.Inheritance and prototype chain1, the understanding of the prototype chainJavaScript does not contain the traditiona
PrototypeIt is also possible for objects to define methods and properties directly through "object. Attribute/method", but it becomes static property and static method, which is called by "." To invoke.But if it is defined by prototype, then it is not possible, the property must be instantiated before it can be calledIn addition, it is not necessary to use prototype
. Prototype = (new A (). Extend (B. Prototype );A brilliant way! It fully demonstrates that a function is actually a variable. Instantiate the Object first, then call extend based on it, overwrite all B. Prototype members to the object
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.