In "JavaScript Play Inheritance (i)", I mainly introduced object camouflage to implement inheritance. Let's start by talking about the pros and cons of this approach.
There is no doubt that this approach is relatively easy to understand, calling the constructor of the parent class in subclasses. In addition, the biggest advantage of this method is that the construction of inheritance can achieve multiple inheritance, review this code:
function A()
{ }
function B()
{ }
function C()
{
this.father=A;
this.father();
delete this.father;
this.father=B;
this.father();
delete this.father;
}
But there are drawbacks to this approach:
Familiar with object-oriented we look at such a section of C # code:
class Program
{
static void Main(string[] args)
{
B b=new B();
bool temp = (typeof(A)).IsInstanceOfType(b);
Console.WriteLine(temp);
}
}
class A
{
public A()
{
}
}
class B : A
{
public B()
{
}
}
What's the result? B Of course is an example of a: