<script type="text/javascript">
function fn(){
this.num = 10;最先找
}
fn.prototype.num = 20;然后
fn.prototype.showNum = function(){}
Object.prototype.num = 30;Object是js最外层
Object.prototype.showNum = function(){} var f1 = new fn(); console.log(f1); //原型链的优先级: 就近原则 //js 基于原型的程序 </script>
<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>