and get the correct output.Three major features of OOP: encapsulation, inheritance, polymorphism; this is just about how inheritance is done in JavaScript (limited to ES5).Inheritance is just a means of code reuse, then how to implement inheritance in JS?Prototype-based inheritanceFirst, the function is also an object, because all functions are instances of function objects, function names, which define fu
JavaScript prototype OOP-are you on the bus? In this article, new drivers with certain vehicle skills can get on the bus. You can take me with old drivers. The copyright belongs to the blog and the author himself. for reprinting and crawling, please indicate the original address of the blog garden, Wu Shuang www.cnblogs.com/tdws.
The JavaScript prototype chain i
JavaScript-based OOP Programming
The simplest way to define an object
var car = {color:"red",drive:function() {alert(this.color + " car moved");}}This method is not very useful because it creates a separate object, which has no connection with any common data structures. To create a second car instance, its structure must be redefined.
Create a new object using the constructor
function Car() {this.colo
---restore content starts---
Creation of objects
Use new to create the object var user = new Object (); User is also an object user.age = 37;//also adds an age attribute to the user object user.name = ' Jay Chou ';Use {} to create an object var user = { ' name ': ' Jay Chou ', ' age ': 35
Classes and constructors
Everything in JavaScript is an object, and all variables and methods can be
imeasure type, and call the method in which to calculate the area and perimeter of the triangle with an edge length of 10.6.5>: In addition to the design of a new class, while inheriting the following interface Iameasure and the 2nd above the imeasure, in addition to providing a specific length of the equilateral triangle side length and the area of the calculation method, but also realized the iameasure of areas () members, Provides a method for calculating the square area.Interface Iameasure{
The examples in this article describe JavaScript's implementation of a method similar to OOP inheritance based on prototype. Share to everyone for your reference, specific as follows:
The public properties (using this. modifier) can be overridden, and private properties (using the Var modifier) cannot be overridden
Subclasses cannot access the private properties of the parent class, and the parent class's methods normally access the private variable
With the prototype feature, you can easily inherit the methods and attributes of the parent class in the subclass. In the following example, Vegetable is treated as the parent class, and Celery is treated as a subclass. Vegetable has the property taste, and the method fun1Celery has the property color and method fun2. If prototype is defined in the same way as Vegetable, it is convenient to inherit the methods and attributes of the parent class in the subclass.
In the following example, Veget
object instance, this property masks the property of the same name saved in the prototype object, remembering that it is masked rather than modifiedDelete property can be deleted by the Delete method to delete the resulting property is the prototype chain inheritance, delete can not delete the prototype chain properties and methods, can only delete the object itself hook4, Hook, prototype chain (also known as __proto__ chain) __proto__ Hook to WHO (see how this object is created, divided into
Before I wrote the class and the prototype, here again the aggregation, before writing about the aggregation, and inheritance I summed up again. There are three ways to inherit in JavaScript, two are written before, but there is no explanation, here are some additional explanations.1. Class inheritance : By invoking the constructor of the parent class within the function object, you get the properties and methods of the parent class. Use CALLH and app
concrete see:
It can be seen from the $p1=new person (); The right side of the equals sign is a real object instance, in the heap memory of the entity, a total of 3 times the new person (), so will be in the heap open 3 space, produce 3 instance objects, each object is independent of each other, using their own space, In PHP, as soon as a new keyword appears, an object is instantiated, creating a space within the heap.
Each instance object in the heap stores properties, for example, the instan
As we said before, the method that declares the method name of "__" in the class (provided to us by PHP) is the method that executes automatically at a certain time under different circumstances, and the "__tostring ()" method is also automatically called, which is called automatically when the object reference is directly exported. We said before that the object reference is a pointer, for example: "$p =new person ()", $p is a reference, we can not use the Echo Direct output $p, this will outpu
This article mainly introduces the concepts related to JavaScript object-oriented programming, such as classes, objects, attributes, methods, and other object-oriented terms, and explains the use of various terms with examples, this is a very good object-oriented getting started tutorial. You can refer to other languages. Although object-oriented JavaScript is di
Reference Type of the JavaScript getting started tutorial and javascript getting started tutorial
Reference Type
A reference type is a data structure used to organize data and functions together. It is also often called a class, but this name is not appropriate. Although ECMAScript is technically an object-oriented lan
JavaScript: elementary JavaScript tutorial (6). The Javascript tutorial uses the internal Object System of the browser to interact with HTML documents. It is used to organize and package related elements for program designers, so as to reduce the work of programmers and impr
JavaScript: JavaScript methods and techniques, Javascript tutorial
This article introduces the javascript log, which I saw on Clang. The author's introduction is quite comprehensive, So I reprinted it to show it to interested friends. Haha ~~~Sometimes you are proficient in
This tutorial provides a relatively complete basic knowledge for those who have not been familiar with JavaScript, but only limited to the basic knowledge.
JavaScript reference
This tutorial provides a relatively complete basic knowledge for those who have not been familiar with J
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.