I. Expansion of the class
1. As long as you expand the prototype class, you can dynamically update to the instance. For example: xxx.prototype.do = function () {//...};
2. It is not recommended to use contaminated JavaScript methods , such as: Object.prototype.methods = function () {//...}; Use the methods in the authoritative guide 9.8.1 to add attributes, such as: Object.defineproperty (//...);
3.
Two. Classes and types
1. isprototypeof ();
2.
Three. Constructor properties
1. type function for judging value types
For example:
function type (obj) {
var t,c,n;
Handling null is worth the case
if (obj = = = null) return "NULL";
Nan and the two situations that are different from yourself
if (obj!== obj) return "NaN";
Not an object, just use this value
if (t = typeof (obj)!== "Object") return t;
Returns the class name of an object, unless it is a
if (c = classof (obj)!== "Object") return C;
If the object constructor name exists, it is returned
if (obj.constructor && typeof obj.constructor = = = "function" && (n = obj.constructor.getName ())) return n;
return "Object";
}; //For Classof (), getName () need to be defined
Four. Duck-type argument
function quacks (obj) {
for (var i = 1; i < arguments.length; i++) {
var arg = arguments[i];
Switch (typeof Arg) {
Case ' string ':
if (typeof Obj[arg]!== "function") return false;
Continue
Case ' function ':
arg = Arg.prototype;
Case ' object ':
For (var m in Arg) {
if (typeof Arg[m]!== "function") continue;
if (typeof Obj[m]!== "function") return false;
}
}
}
return true;
};
var f = function fn (x) {return x*x}; Alert (quacks (f)); //True
201507010852_ "JavaScript authoritative Guide (sixth Edition)-the type function for judging value types, duck-type argument" (p210-217)