instanceof运算符希望左操作数是一个对象,右操作数表示对象的类:如果左侧的对象是右侧类的实例,则返回true,否则返回false.由于js中对象的类是通过初始化它们的构造函数来定义的,因此instanceof的右操作数应当是一个函数.比如: var d = new Date(); d instanceof Date; //true d instanceof Object; //true d instanceof Number; //false 所有对象都是Object的实例,intanc…
in运算符希望它的左操作数是一个字符串或可以转换为字符串,希望他的又操作数是一个对象:如果右侧对象拥有一个名为左操作数值的属性名,那么表达式返回true: var point = {x:1,y:1}; "x" in point //true "z" in point //false "toString" in point //true var ary = [1,2,3]; "0" in ary; //true,ary含有索引0…
var i = 2; Number.prototype.valueOf = function() { return i++; }; var a = new Number( 42 ); if (a == 2 && a == 3) { console.log( "Yep, this happened." ); } ============================ "0" == null; // false "0" == und…
1.What is the 'instanceof' operator used for? stackoverflow的一个回答:http://stackoverflow.com/questions/7313559/what-is-the-instanceof-operator-used-for instanceof keyword is a binary operator used to test if an object (instance) is a subtype of a given…