zoukankan      html  css  js  c++  java
  • javaScripte 创建对象。。

    <!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=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
     <script type="text/javascript">
     //用函数创建一个person对象
     function Person(name,age){
      this.name=name;
      this.age=age;
      this.setName=function setName(name){
       this.name=name;
      };
      this.getName=function getName(){
       return this.name;
      };
      this.setAge=function setAge(age){
       this.age=age;
      };
      this.getAge=function getName(){
       return this.name;
      };
      this.toString=function toString(){
       return "[ name:  "+this.name+","+" age:   "+this.age+"]";
      };
     };
     //使用原型函数
     Person.prototype.show=function(){
      alert("person run");
     };
     //创建对象
     var p=new Person("wangwu",22);
     var p1=new Person("zhangsan",23);
     alert(p.name);
     alert(p1.toString());
     for ( var x in p) {
      alert("x="+p[x]);
     };
     with(p){
      name="dalang";
      age=21;
     };
     alert(p.toString());
     </script> 
    </body>
    </html>

  • 相关阅读:
    简化单例模式
    static
    单例模式之懒汉模式
    Car race game
    poj-2403
    poj-2612
    poj-1833
    poj--2782
    poj--2608
    poj--3086
  • 原文地址:https://www.cnblogs.com/daoxiang1992/p/5837869.html
Copyright © 2011-2022 走看看