JavaScript Object-oriented Programming (II): Inheritance of constructors
The first part of the series focuses on how to "encapsulate" data and methods, and how to generate instances from prototype objects.
Today's introduction is about five ways to "inherit" between objects.For example, there is now a constructor for an "animal" object.
function Animal () {
This.species = "
Sometimes the parent class object needs to be pointed to the subclass object, and sometimes the parent class object needs to be converted to the subclass object. For example, we can say that a dog is an animal and a dog, but the premise is that we must know that a dog must be an animal, the animal must be a dog. The following describes how to direct the parent cl
, if you write a tree traversal algorithm, you can use it to process any directed acyclic graph.
Future Tense considerations increase the reusability, maintainability, and robustness of your code, and are easy to modify when the environment changes. It must be used with the constraint condition for temporal. Too many programmers only focus on their current needs, but they sacrifice the long-term viability of software.Be a different person, be a defectTo develop programs in the future tense.
It
Question settingsThe farmer wants to ship cats, dogs, and fish on the left bank to the right bank by boat. During the transportation process, only one animal can be shipped at a time, and the farmer can cross the river by air. When a person is not on the bank, the dog will bite the cat and the cat will eat fish. When a person is on this bank, there will be no conflict. Use an object-oriented design to solve such problems.
Analysis: According to the Qu
) {
THIS.name = name;
This.color = color;
This.type = "Cat animal";
This.eat = function () {alert ("Eat Mouse");
}
The same approach is used to generate an instance:
var cat1 = new Cat ("Da Mao", "Yellow");
var cat2 = new Cat ("Er Mao", "Black");
alert (Cat1.type); Cat Animals
Cat1.eat (); Eat mice
There seems to be no problem on the surface, but there is a big drawback in actually doing so. That is,
program follow the principle of a single responsibility, you need to decompose class C into two classes C1 and C2, respectively, responsible for R1, R2 two responsibilities. But when the program has been written, it's too time-consuming. So it is a good choice to simply modify Class C and use it to take charge of two duties, although it is contrary to the principle of single responsibility.To illustrate:Class Animal{public void Breathe (String
", "Yellow");
var cat2 = new Cat ("Er Mao", "Black");
alert (cat1.name); Da Mao
alert (Cat1.color); Yellow
At this point, CAT1 and Cat2 automatically contain a constructor attribute that points to their constructors.
Alert (Cat1.constructor = = Cat); True
Alert (Cat2.constructor = = Cat); True
JavaScript also provides a instanceof operator that validates the relationship between a prototype object and an instance object.
Alert (cat1 instanceof Cat); Tr
1. Error descriptionUsing catalina_base: "D:\NetBeans\apache-tomcat-8.0.12" Using Catalina_home: "D:\NetBeans\apache-tomcat-8.0.12" Using Catalina_tmpdir: "D:\NetBeans\apache-tomcat-8.0.12\temp" Using Jre_home: "D:\Java\jdk1.7.0_67" using CLASSPATH: "D:\netbeans\apache-tomcat-8.0.12\bin\bootstrap.jar;d:\netbeans\apache-tomcat-8.0.12\bin\tomcat-juli.jar" 25- JAN-2015 19:08:33.046 INFO [main] org.apache.catalina.core.AprLifecycleListener.init Loa
add and modify files in/tmp (because the permissions are all rwx), but only the file/directory creator and Root can delete their own directories or files.Note: This sbit does not work for files.Suid/sgid/sbit permission settingsSimilar to what we said earlier, there are two ways of rwx, one is in characters, and the other is in numbers.4 for SUID = U+s2 for SGID = G+s1 for sbit = O+tLet's take a look at how to set it up and see how it works.First look at the function and setting of SUID[Email p
Solve the problem of using ultra-large space bitsCN.com
In recent months, servers have always been on the machine frequently, leading to unguaranteed availability of the bill lid. But it is also strange, when the server can be normally connected, Nginx also seems to be normal, but the PHP-FPM lost response. Later, I accidentally found out:Rootfs 7.7G 7.7G 0 100%/
The root directory is full! It is considered that there are too many logs and the logs are cleared. However, logs are full every week.
:
[SQL statement 1]Union[SQL statement 2]Suppose we have two tables,
Store_informationTable
Store_name
Sales
Date
Los Angeles
$1500
Jan-05-1999
San Diego
$250
Jan-07-1999
Los Angeles
$300
Jan-08-1999
[SQL statement 2]Suppose we have two tables,
Store_informationTable
Store_name
Sales
Date
Los Angeles
$1500
Jan-05-1999
San Diego
$250
Jan-07-1999
Los Angeles
$300
Jan-08-1999
One limitation of union is that two SQL statements produce a field that needs to be the same type of data. In addition, when we use the Union directive, we will only see different data values (similar to SELECT DISTINCT). The union simply joins the two results together to show that it is not linked to two tables.
The UNION syntax is as follows: [SQL statement 1]
UNION
[SQL Statement 2] Suppose we have the following two tables,
Store_information form Store_name Sales Date
Los Angeles $1500
two tables ........ The syntax of UNION is as follows:[SQL statement 1]UNION[SQL Statement 2] Let's say we have the following two tables,
store_information Form
Store_name
Sales
Date
Los Angeles
$1500
jan-05-1999
San Diego
$
jan-07-1999
the relationship between a prototype object and an instance object.
Alert (cat1 instanceof Cat); True
Alert (cat2 instanceof Cat); True
Four, the problem of the structure function patternThe constructor method works well, but there is a problem of wasting memory.See, let's add a constant Cat property type (kind) to the object, and add a method eat (eat). Then the prototype object Cat becomes the following:
function Cat (name,color) {
THIS.name = name;
This.col
Like other high-level languages, JavaScript also has the new operator, and we know that the new operator is used to instantiate a class, allocating an instance object in memory. But in JavaScript, all things are objects, why do they have to be created by new? This article will bring you together to explore the mysteries of new in JavaScript ...
First, recognize the new operator
function Animal (name) {
this.name = name;
}
Animal.color
virtual void fun ();
virtual void fun1 ();
};
Implementation of CA,CB Class
...
void Main ()
{
CA A; Not allowed because there are pure virtual functions in the class CA
CB b; OK, because there is no pure virtual function in class CB
...
}
---------------------------------------------------------------
The use of virtual functions in the middle of polymorphism:
Polymorphism is generally done by pointing to a pointer to a base class.
Dog Mydogwangwang;
Mydogwangw
the leaf node is connected in an orderly manner through a two-way linked list. At the same time, the data table is different from the index leaf node, the data in the table is unordered. They are not all stored in the same table block and there is no connection between the blocks.
In general, the index stores the physical address values of specific data.
Index type
We know that there are two types of indexes: clustered index and non-clustered index.
Clustered index: physical storage is sor
contains four fields: Animal,name,sex and age, and uses animal as the indexed column, with the following SQL code:
Copy Code code as follows:
-----------------------------------------------------------
----Create t_pet table in tempdb.
-----------------------------------------------------------
Use tempdb
CREATE TABLE T_pet
(
Animal V
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.