javascript 面向对象实例

直接上源码吧:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript" src="jquery.js"></script>
<title>无标题文档</title>
<script type="text/javascript">
 (function()
  {
    var ntx=function()
    {
      return this;
    }
     ntx.prototype={
       id:"test",
      aa:function(bb)
      {
        alert(bb);        
      },
      cc:function(dd)
      {
       alert(dd);
      }       
    }
    window.test = ntx;
   })();
</script>
</head>

<body>
 <script>  
 (function(){
    var xt = new test();
    xt.aa("xx and xx");
    xt.cc("这是一个测试!");
    xt.cc(xt.id);
  })();
 </script>
</body>
</html>

注意:最后xt是new出来的且要将ntx保存到window变量中

原文地址:https://www.cnblogs.com/xlhblogs/p/2249196.html