会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
红色石头
热情的血液+石头的冰冷
博客园
首页
新随笔
联系
管理
订阅
Javascript中定义类
动态原型方法:在构造函数内定义非函数属性,而函数属性则利用原型属性定义。
function
Car(sColor,iDoors,iMpg)
{
this
.color
=
sColor;
this
.doors
=
iDoors;
this
.mpg
=
iMpg;
this
.drivers
=
new
Array(
"
Mike
"
,
"
Sue
"
);
if
(
typeof
Car._initialized
==
"
undefined
"
)
{
Car.prototype.showcolor
=
function
()
{
alert(
this
.color);
}
;
Car._initialized
=
true
;
}
}
function
test()
{
var
oCar1
=
new
Car(
"
red
"
,
4
,
23
);
alert(oCar1.drivers);
oCar1.showcolor();
}
posted on
2007-09-10 23:04
红色石头
阅读(
228
) 评论(
1
)
编辑
收藏
举报
刷新页面
返回顶部