_面向对象的相关属性和方法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> //1 hasOwnProperty 查看某个属性是不是对象上的 如果是 返回true 如果不是返回false function fn(){ //this.num = 10; } // fn.prototype.num = 20; // fn.prototype.age = 30; fn.prototype = {//这样写了以后 构造函数已经被改变 constructor:fn, num:20, age:30 } //怎么用 var f1 = new fn(); // alert(f1.num); // console.log(f1.hasOwnProperty("num")); //2 constructor 查看对象的构造函数 var str = []; // console.log(f1.constructor); //3 instanceof 是一个运算符 表示对象与构造函数在原型链上是否有关系 function fn2(){} var f2 = new fn2(); var str = "sss"; var arr = new String( "dd" ); console.log(arr instanceof String); //包装对象 基本类型才有 </script> </head> <body> </body> </html>