在Javascript中定义对象类别

时间:2006-12-22    点击:185   
From: JavaEye.com

注意JavaScript中对象类别的定义,使用function来定义对象类别,初始化对象使用new操作符
function Person(name, age) {
 this.name = name;
 this.age = age;
 this.toString = function() {
 document.writeln("[name]:"+this.name+"<br>"+"[age]:"+this.age);
 }
}

完整的简单HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JavaScript</title>
<script language="javascript" type="text/javascript">
function Person(name, age) {
 this.name = name;
 this.age = age;
 this.toString = function() {
 document.writeln("[name]:"+this.name+"<br>"+"[age]:"+this.age);
 }
}
</script>
</head>

<body>
<script type="text/javascript">
 var person = new Person();
 person.name="robbin";
 person.age=30;
 person.toString();
</script>
</body>
</html>
jQuery的一些注意
基于prototype的validation.js发布2.3.4新版本,让你彻底脱离表单验证的烦恼
鼠标移动到一张图片时变为另一张图片
获取任意Html元素与body之间的偏移距离 offsetTop、offsetLeft (For:IE5+ FF1 )[
获取Javscript执行函数名称的方法
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved