for-in.js // for in hasOwnProperty prototypefunction P(){ this.name = 'sigma';}P.prototype.age = 18;var a = new P();// code 1for( let key in a){ console.log( key );}// code 2for (let key in a) { a.hasOwnProperty( key ) console.log(key);}` 伪
// for in & hasOwnProperty & prototype function P(){ this.name = 'sigma'; } P.prototype.age = 18; var a = new P(); // code 1 for( let key in a){ console.log( key ); } // code 2 for (let key in a) { a.hasOwnProperty( key ) && console.log(key); }`伪造hasOwnProperty
function P(){ this.name = 'sigma'; } P.prototype.age = 18; P.prototype.hasOwnProperty = function( ){ // 伪造 return false; } var a = new P(); for( let key in a){ a.hasOwnProperty( key ) && console.log(key); }