In the first two articles, we introduced the construction inheritance and the prototype inheritance. Now that we have finished writing the two remaining ones, these two applications are rarely applied to the first two, so I call them the Non-mainstream inheritance approach.
First, we look at Non-mainstream succession One: instance inheritance method.
I do not say so much nonsense, since it is Non-mainstream inheritance, it must not be used, since not commonly used still exist, there is only one factor, he used for specific occasions. Instance inheritance, which is mainly used for the inheritance of core objects, is the only way to resolve core object inheritance so far.
The core object of inheritance has a certain value, such as the Error object, our company may have to implement an error class to simplify future development, then I will use the instance inheritance method to inherit the error.
The code is as follows:
function ExtendingError(mes)
{
var instance=new Error(mes);
instance.NewError=function(){
alert("Your Error is "+mes);
}
return instance;
}
Okay, under test:
var e=new ExtendingError("Your number is less than one");
e.NewError();
alert(e.toString());
The results satisfied US:
Good, nonsense not much to say, this is a non-mainstream way of inheritance, basically only for the core object of inheritance, remember!