js如何判斷屬性是本身具有還是繼承別人的

antzone發表於2017-04-03

本章節介紹一下如何屬性是本身自有的還是繼承別人的,下面就通過程式碼例項做一下介紹。

程式碼例項:

[JavaScript] 純文字檢視 複製程式碼
function Antzone(){
  this.webName="螞蟻部落";
  this.url="softwhy.com"
}
Antzone.prototype={
  age:3
}
var antzone=new Antzone();
console.log(antzone.hasOwnProperty("webName"));
console.log(antzone.hasOwnProperty("age"));

程式碼比較簡單,更多內容可以參閱js hasOwnProperty()一章節。


相關文章