最简单的javascript对象实例代码

  作者:bea

<html> <body> <script> function user() { this.age=21; this.name="zhangsan"; this.say=function(){ alert("hello"); } } var u = new user(); alert(u["age"]); alert(u.name); u.say(); </script> </body> </html>



<html>
<body>
<script>
function user()
{
this.age=21;
this.name="zhangsan";
this.say=function(){
alert("hello");
}
}
var u = new user();
alert(u["age"]);
alert(u.name);
u.say();
</script>
</body>
</html>




[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]

JavaScript面向对象的两种书写方法以及差别

http:///article/13211.htm
JavaScript 面向对象入门精简篇

http:///article/17541.htm



有用  |  无用

猜你喜欢