我讀的地方,Object.__proto__
和Object.prototype
指向同一件事和Object.prototype
是標準的方式,但昨晚我試圖繼承與Object.prototype
一類,但它沒有工作,然後我試圖找出是否同時Object.__proto__
和Object.prototype
指向同一事物或not.To我吃驚的是Object.prototype不能正常工作,但是Object .__ proto__工作原因是什麼?如何讓我的代碼在所有瀏覽器中工作?
alert(Object.__proto__===Object.prototype);
在alertbox 顯示false
所以要找出哪一個作品我寫了下面的代碼
function Cx(){
this.objName="i m X";
this.prototype={ };
this.prototype.getMyName=function(){
alert(this.objName);
}
this.__proto__={ };
this.__proto__.hMyName=function(){
alert("I am hMyName");
}
}
function InheritCx(){
//var y=new Cx();
this.objName="I am InheritCx";
this.__proto__=new Cx();
}
y= new InheritCx();
y.hMyName();//displayes "I am hMyName" in alertbox when using chrome or mozilla
y.getMyName();//displays an error in chrome and mozilla
這兩者之間有什麼區別,爲什麼標準代碼不起作用? 此外,我有興趣知道在大多數瀏覽器(IE 6-8,9,10,chrome,firefox,mozilla,opera和webkit)中做什麼樣的原型繼承工作?
'對象.__ proto__ === Function.prototype',至少在Chrome(見下面的評論) – 2013-05-05 05:22:51
*「我讀的地方,'對象.__ proto__'和'Object.prototype'指向一樣...」*。不。 'Object'是一個函數,所以'Object.__ proto__'將是'Function.prototype'。 – 2013-05-05 05:22:53
@FabrícioMatté很酷。在我們實際使用它之前,我們需要等待的IE版本是什麼(嚴重問題)? – 2013-05-05 05:27:41