JavaScript objects and inheritance, javascript inheritance
This article records a JavaScript Object definition and inheritance writing method, which is also widely used at present. 1. Define the object (mixed constructor and proto
let the prototype object be equal to another instance of the type?Obviously, the prototype object at this point will contain a pointer to another prototype, and a pointer to another constructor is also included in the other prototype.If another prototype is another type of example, then the relationship is still established, so that the level of progression, constitutes an example and prototype chain.This
Object orientedSeveral important features of object-oriented thinking (requirements for classes): Abstraction-encapsulation, information hiding (internally implemented methods and data hiding, defining open interfaces) Inheritance-subclasses can use the resources of the parent class, and can customize their own resources, including methods and data Polymorphic-Overloaded (function with the same name), overwrite (overriding parent-class function on the
Simple and clear useJavascriptSingle inheritance and multi-Inheritance
By Shen Dongliang http://blog.csdn.net/shendl/
Javascript is a powerful multi-generic programming language. It integrates process-oriented, object-oriented, and functional programming with powerful performance capabilities.
Javascript is essentiall
JavaScript is essentially a functional programming language, a descendant of Lisp, and adds elements of object-oriented programming, giving up some of the elements of a functional language that are difficult to understand.
The functional programming language can realize object-oriented programming, this is no doubt, Curry method can realize to the class and object simulation. But JavaScript provides anothe
JavaScript is a powerful multi-generic programming language. It integrates process-oriented, object-oriented, and functional programming with powerful performance capabilities. JavaScript is essentially a functional programming language. It is a descendant of Lisp. At the same time, it adds an object-oriented programming element, giving up some obscure functional language elements.
The functional programmi
reference in the instance and can therefore be shared by multiple instances.Both have advantages and disadvantages, and practical applications are mostly mixed applications.Here's an example of mixing the two to understand:function A (x) { This. x =x; } a.prototype.a="a"; function B (x, y) { This. y =y; A.call ( This, x);//class Inheritance} b.prototype.b1=function () {alert ("B1"); } B.prototype=NewA ();/
Multiple inheritance #include650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/A5/06/wKioL1m2Z4-j-hVCAABD_80oOIY066.png-wh_500x0-wm_ 3-wmp_4-s_423864483.png "title=" 111.png "alt=" Wkiol1m2z4-j-hvcaabd_80ooiy066.png-wh_50 "/>This article is from the "10628473" blog, please be sure to keep this source http://10638473.blog.51cto.com/10628473/1964414An example of virtual
Javascript is essentially a function.
Programming Language It is the descendant of Lisp. At the same time, it adds an object-oriented programming element, giving up some obscure functional language elements.
The functional programming language can implement object-oriented programming, which is unambiguous. The curry method can simulate classes and objects. However, JavaScript provides another method t
JavaScript is essentially a functional programming language. It is a descendant of Lisp. At the same time, it adds an object-oriented programming element, giving up some obscure functional language elements.The functional programming language can implement object-oriented programming, which is unambiguous. The Curry method can simulate classes and objects. However, JavaScript provides another method to impl
Speaking of "the basic mechanism of JavaScript archetype inheritance", this article will specifically say the inheritance of constructors.
Starting with a simple example, create a people constructor that describes humans:
Copy Code code as follows:
function people () {
This.race = ' stupid human ';
The old question, most people also may not be able to understand systematically. JavaScript language is not good for inheritance, it requires engineers to implement a complete set of inheritance mechanism. Here we have a system that grasps the techniques of using JavaScript inherit
Speaking of the basic mechanism of JavaScript prototype inheritance, this article details the inheritance of constructors.From a simple example, create a People constructor that describes humans:Copy codeThe Code is as follows:Function People (){This. race = 'stupid human ';} Then, create the Yellow constructor that de
.sex itself does not have a value, it is read from the constructor's prototype property, and so on, and so on, up until the object.
Note: Assign a value to an object using "null" to destroy the custom object and free the memory resource.
The prototype is read from the prototype chain and written to yourself.
A small example of inheritance
The code is as follows
Copy Code
//
super method. It allows a method to call the method of the parent class (the name is changed to avoid conflicts with reserved words ).
We can write it like this
The Code is as follows:
MyZParenizor = new ZParenizor (0 );MyString = myZParenizor. toString ();
This time, myString is "-0 -".
JavaScript does not have classes, but we can program to achieve this goal.
Multi-Inheritance
By operating on the pro
(anotherperson.name); Greg alert (anotherperson.friends); Shlby,huu,dima,rob,barbie alert (yetanotherperson.name); Linda alert (yetanotherperson.friends); Shlby,huu,dima,rob,barbie alert (person.name); Nico alert (person.friends); Shlby,huu,dima,rob,barbieThis archetypal inheritance requires that you have an object that can be used as the basis for another object. With such an object, you can pass it to the object () fun
sub2 = new SubClass(); console.log(sub1.name);//woman console.log(sub2.bra);//["a","b","c"]
Note: add an element to the array. All instances inherited from the SuperClass will be affected. However, modifying the name attribute will not affect other instances because the array is of reference type, name is the basic type.How can we solve the problem of instance sharing? Let's take a look...
Constructor stealing)
Just as we have introduced that prototype definition objects are rarely used separ
How JavaScript implements inheritance (six methods) and six javascript methods
Most OO languages support two inheritance Methods: interface inheritance and implementation inheritance, while interface
Personal Summary: Reading this article takes 15 minutes, the article mainly explains the working principle of Babel and typescript, (such as the conversion of ES6 class, is to convert the original ES6 code to ES5 code, 这些代码中包含着类似于 _classCallCheck 和 _createClass这样的函数,而这些函数已经 pre-defined in the standard libraries of Babel and typescript, and then processed). By the way object.create this method, such as having a obj:{name: ' Is Ho ', f:function () {alert (1)}}var a = object.create (obj)At this poi
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.