标题: javascript 函数定义的方式
- 小寒 2008-04-10 09:27 阅读:373
- 评论:3 查看评论 | 添加评论
函数本来也是种对象,如下为定义类型名为people的对象:
1 有参的构造方法
function people(name){
this.name=name;
}
2 给对象添加一个属性(方法)
people.prototype.getName = function() {
return this.name;
}
使用:
1 实例化一个对象
var me=new people('chenxiaowen');
2 调用事例的方法me.getName()
alert(me.getName());
查看评论 | 添加评论
返回顶部 | 返回首页