Discover object prototype hasownproperty call, include the articles, news, trends, analysis and practical advice about object prototype hasownproperty call on alibabacloud.com
1. Object Inheritance in js
There are three inheritance methods in js:
1. prototype inheritanceCopy codeThe Code is as follows:2. constructor implementation inheritanceCopy codeThe Code is as follows:3. call and apply implement inheritanceCopy codeThe Code is as follows:Ii. call and apply usage (details)
In js, both
prototype object. The relationship between the Person Function and Its prototype object is shown in. We call this memory model the first State of the prototype.
Then we set the attributes and methods for the Person function throu
in toy) {Each object has a isprototypeof method that determines whether the current object is a prototype of another object/*every object also gets the isPrototypeOf () method. * This method tells your whether that specific object
First, the prototype chain (family genealogy)
Concept: JS inside the object may have a parent object, the parent object will also have a parent object, ... Ancestors
Root: Inherit
Property: There is almost always a __proto__ property in the
This article mainly introduces several usages of JS inheritance (Apply,call,prototype) the need for friends can come to the reference, I hope to be helpful to everyoneOne, JS in object inheritanceThere are three ways of inheriting in JS1.js Prototype (prototype) Implementati
This article goes to: TjyoungIt's been a while lately. The third edition of Nicolas Zecas's advanced Programming (Red Book) The sixth chapter: Object-Oriented programming, now the summary of the things to share with you.The main contents are as follows:1. Factory mode2. Constructor mode3. Prototype mode4. InheritanceFirst, the factory modelAn object is created in
" (instance), and it relies on a very peculiar "prototype chain" (prototype chain) pattern to implement inheritance.Prototype is actually a property of the constructor.All instance objects need to share the properties and methods that are placed inside the object, and those that do not need to be shared are placed inside the constructor.Once the instance
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 yellow hair wash cut no matter, that the object instance cannot change the properties of the
synthesis lookup }}functionBar () { This. S_name = "Bar";}varf =NewFoo ("Foo_arg1", "FOO_ARG2");varb =Newbar (); f.f_func.apply (b, ["Apply_arg1", "apply_arg2"]);//call the F_func method in object F of type Foo, but the this.s_name is actually the bar type Object B.Output:bar apply_arg1 apply_arg2The example of inheritance does not write, as with
return value, if the object is returned, the newly created object will not be returned, instead of the object after returnConstructor (constructor) execution steps1. Create an object using the New keyword2. Call the constructor to assign the
functionfunction foo () {return 0;}Its prototype chain is: Foo----> Function.prototype----> object.prototype----> NullWhen we access the properties of an object, the JavaScript engine looks for the property on the current object, and if it is not found, it is found on its prototype
Properties of the function length, prototype, and Method call (), apply ()Length refers to the number of arguments that the function expects to pass in.function Fun0 () {}//0function Fun1 (NUM1) {}//1function Fun2 (num1,num2) {}//2Prototypefunction MyObject (name, size) { This. Name = name; This. size = size; }var obj = new MyObject ();MyObject.prototype.color = "Red"; alert (Obj.color); RedMyObject.protot
(first,last,id){
//initializepropertieshere
}
KevLinDev.extend(Employee,Person);
We first created a convenient function to set our inheritance chain. We need to make the attributes of baseclass equal to those of subclass. Remember, when we call "new", the prototype property will be copied to "_ proto" of an instance, and the inheritance chain will be connected ). However, we cannot allow
plan to complete this note in the following order:
Idea.
Property replication and inheritance.
This/call/apply.
Closed Packet/getter/setter.
Prototype
Object-oriented simulation.
The basic mechanism of jquery.
jquery selector.
jquery Tool method.
jquery-extends at the class level.
jquery-extends at the "
Object is used by Prototype as a namespace; that is, it just keeps a few new methods together, which are intended for namespaced access (I. e. starting with "Object .").The namespace mentioned above is equivalent to the static class in C #. It provides the meaning of tool functions, and the namespace in C # should not be a concept. Because the namespace in C # wi
above code, the last output is true, the principle is: Access an instance property or method in read mode, now search in instance, search is not to follow the prototype chain up to find,instance->subtype.prototype-> Supertype.prototype. If the return undefined is not found.In JS object-oriented (1) We have already talked about the problem of the prototype chain,
1. When you use for-in to traverse an object (for-in is better not to traverse an array, but to traverse an array, you are advised to filter out the interference of the prototype chain of the object.
If (Object. prototype. clone = 'undefined') {
function person (fullname, sex) { This . fullname = fullname | "unknown"; This . sex = sex | "male"; This . speek = function () { console. log ( This . fullname + "is speeking"); } function staff (ID, title, fullname, sex) { This . id = ID | 1001; This . title = title | "Developer"; } New person (); var S1 = New staff (99," manager "," Eva ", "female"); console. log (s1.fullname); /// => unknown
It is found that (...) You cannot assign values to fullname and sex beca
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.