//构造函数
function d(name,age){
this.name = name;
this.sex= sex;
}
//在函数原型链上添加属性和方法
Dog.prototype.type = 'xxx';
Dog.prototype.fun = function(){
console.log('mmm');
}
//实例化对象
var d1= new d('小明','男');
console.log(d1.name);
console.log(d1.sex);
- //属性探测
- // in : 操作符会检查自有属性和原型属性
- // hasOwnProperty : 只检测自有属性
- console.log( 'name' in Dog); //true
- console.log( 'toString' in Dog); //true
- console.log( Dog.hasOwnProperty('name')); //true
- console.log( Dog.hasOwnProperty('toString')); //false
- //删除属性
- // delete dog.name; // true
- console.log(Object.getOwnPropertyDescriptor(moudel,'name'));