========================================================== ==========================================================
Qomolangma openproject v0.9
Category: rich Web Client
Key words: JS Oop, JS framwork, rich Web Client, Ria, Web component,
Dom, dthml, CSS, JavaScript, JScript
Project Initiation: aimingoo (aim@263.net)
Project Team: aimingoo, Leon (pfzhou@gmail.com)
Contributor: Jingyu (zjy@cnpack.org)
========================================================== ==========================================================
VIII. Javascript object-oriented support
~~~~~~~~~~~~~~~~~~
(Continued)
2. Javascript object-oriented support
--------
(Continued)
5). calculation using the instanceof keyword
------
The instanceof keyword is provided in JavaScript to detect the instance type. This is discussed before
I have already talked about its "Five identities. But the problem with instanceof is that it always lists the whole
The prototype chain is used to detect the type (the Principles of prototype inheritance are described in the "constructor and destructor" section), for example:
//---------------------------------------------------------
// Instanceof usage Problems
//---------------------------------------------------------
Function myobject (){
//...
}
Function myobject2 (){
//...
}
Myobject2.prototype = new myobject ();
Obj1 = new myobject ();
Obj2 = new myobject2 ();
Document. writeln (obj1 instanceof myobject, '<br> ');
Document. writeln (obj2 instanceof myobject, '<br> ');
We can see that both obj1 and obj2 are myobject instances, but they are generated by different constructors.
. -- Note that this is correct in the object-oriented theory: Because obj2 is a subclass of myobject
So it has the same features as obj1. This is one of the manifestations of obj2 polymorphism in applications.
However, even so, we must also face the problem of how to know whether obj2 and obj1 are
What about instances of the same type? -- That is to say, the constructor is the same?
The instanceof keyword does not provide such a mechanism. Which of the following is the ability to implement such detection?
Object. constructor attribute. -- But remember that it is far more difficult to use than you think.
Okay. Here is the first question. Constructor attributes already involve the issue of "constructor and constructor,
Let's talk about this later. "Prototype inheritance" and "constructor and destructor" are Javascript OOP
And critical issues ".
6). null and undefined
------
In JavaScript, null and undefined once confused me. The following text is helpful
You can better understand it (or confuse you ):
-Null is the keyword; undefined is an attribute of the global object.
-Null is an object (empty object with no attributes or methods); undefined is an undefined class.
Type value. Try the following code:
Document. writeln (typeof null );
Document. writeln (typeof undefined );
-In the object model, all objects are instances of objects or their subclasses, except for null objects:
Document. writeln (null instanceof object );
-Null "equivalent (=)" indicates undefined, but not "full equivalent (=)" indicates undefined:
Document. writeln (null = undefined );
Document. writeln (null = undefined );
-During the operation, both null and undefined can be converted to false, but not equal to false:
Document. writeln (! Null ,! Undefined );
Document. writeln (null = false );
Document. writeln (undefined = false );