Bootstrap

js静态 public private 属性与方法

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>类.html</title>
  </head>
  <script type="text/javascript">
 
  var StaticClazz = {   //static property and method
       name : "张三",
       show : function(){
            alert(this.name);
       }
  }
  StaticClazz.show(); // 静态类不需要实例化
 
  function Emp(){
      this.name  = "李四";   //public property
      age = 10;             //private property
  }
  Emp.prototype  = {
      sex  : '男',
      show : function(){
        alert(this.name + " " +age);
      }
  }
 
  Emp.prototype.sex = "女";
 
  var emp = new Emp;
  alert("name: " + emp.name + " age: " + emp.age + " sex: " + emp.sex);
  emp.show(); 
  </script>
  <body>
  </body>

</html>




转载请著名出处: 找网网-职业(程序员 UI设计 产品经理...)常用网站导航

;