javascript,工厂函数

来源:互联网 发布:php积分系统源码 编辑:程序博客网 时间:2024/05/29 04:06
<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
    //工厂函数
      function createStudent(id,name,age)
      {
        var student=new Object();
        student.id=id;
      student.name=name;
      student.age=age;
      student.study=function()
      {
       alert('身份:'+this.id);
        alert('姓名:'+this.name);
        alert('年龄:'+this.age);
      };
      return student;
      }
      var stu1=createStudent('001',"李兴华",50);
      var stu2=createStudent('002',"李兴华",51);
      stu1.study();
      stu2.study();
    </script>
  </head>
  <body>
    
  </body>
</html>
0 0