JS面向对象的标准写法 收藏
view plaincopy to clipboardprint?
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
<mce:script type=text/javascript><!--
var person=function(name,age){//定义对象构造方法
this.name=name;
this.age=age;
}
person.prototype={ //封装方法
getName:function(){
alert(this.name);
},
getAge:function(){
alert(this.age);
}
}
function test(){//声明调用
var man=new person('jack',12);
man.getName()
man.getAge()
}
var test2 ={ //类似静态方法 调用直接:test2.te();即可
te:function(){
alert();
},
te1:function(){
alert();
}
}
// --></mce:script>
</head>
<body>
<input type=button οnclick="test()"/>
</body>
</html>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jaylongli/archive/2009/10/30/4746958.aspx