asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0

类prototype写在类内就不能重写和覆盖,只能添加和修改prototype的属性。这跟本地对象类的prototype为什么是只读的是一个道理。所以,由此可以猜测本地对象类的结构类似于:
function Class()
{
 this.property1=xxx;
 if(typeof Class._initialized==undefined)
 {
 Class.prototype.method1=function(){[native code]};
 Class._initialized=true;
}
}
本地类就像:
<script>
function b()
{
this.b=2;
}
function a()
{
 this.a=1;
a.prototype=new b();//继承不了
}

var o=new a;
alert(o.b);//所以结果为undefined
</script>
用户自定义类就像:
<script>
function b()
{
this.b=2;
}
function a()
{
 this.a=1;
}
a.prototype=new b();//写在外面 可以重写覆盖

var o=new a;
alert(o.b);//所以结果为2
</script>

posted on 2007-01-30 15:28 汪杰 阅读(250) 评论(0)  编辑 收藏 引用 所属分类: javascript
只有注册用户登录后才能发表评论。

<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 457967
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜