function Student(name,age){ this.name=name; this.age=age; } function Man(name,age){ this.name=name; this.age=age; } var stu=new Student("dc",24); var man1=new Man("mm",34); alert (stu instanceof Student); //返回true alert(man1 instanceof Student); //返回false alert(man1 instanceof Man); //返回true alert (typeof(stu)); //返回object alert(typeof(man1)); //返回 object
<script> var str=new String("hello"); alert(typeof(str));//返回string(无论引用什么类型都返回的是object) alert(str instanceof String);//返回true,明确对象特定类型 </script>
<script type="text/javascript"> var a = function () {}; var b = function () {}; b.prototype = new a; var c = new b; var d = new a; alert(c instanceof a); //true alert(d instanceof a); //true alert(a instanceof Function); //true alert({} instanceof Function); //false a.prototype = {}; //改变原型链 alert(c instanceof a); //false alert(d instanceof a); //false </script>
测试文件名为 demo.htm <script type="text/javascript"> var a = new window.ActiveXObject('Microsoft.XMLHTTP'); a.open('get', 'demo.htm', false); a.send(null); alert(typeof a.responseBody); //unknown </script>