我读的地方,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