Delete is an attribute of an object. For example, for an object,
Var obj = {key: 5 };
Delete obj. key is to delete the key attribute of the object. This is no problem, but it is worth noting that the prototype object of the object also has this attribute.
Copy codeThe Code is as follows:
Var A = function (){};
A. prototype. testMe = true;
Var a = new ();
// Overwrite the prototype Property
A. testMe = true;
If (a. testMe ){
// Some key code...
//....
// Delete this attribute
Delete a. testMe;
}
// Section 2 ---------------------------
// In other modules
If (a. testMe ){
// Some key code...
//....
}
The second paragraph is worth noting. Do not think that testMe IN a does not exist if it has been deleted, so. testMe is undefined, which is false. In fact, it still exists through prototype access, or true!
This is just a move.
// Appendix:
Check whether an object has a property, including the prototype chain:
If ('attrname' in obj )...
Check whether an object has a certain attribute, which belongs to the object rather than the prototype chain:
Obj. hasOwnProperty ('attrname ')