zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然 JAVASCRIPT开发学习:prototype(原型对象)

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <h2>JavaScript 对象</h2>
    
    <p id="demo"></p>
    
    <script>
    function Person(first, last, age, eye) {
      this.firstName = first;
      this.lastName = last;
      this.age = age;
      this.eyeColor = eye;
    }
    
    var myFather = new Person("John", "Doe", 50, "blue");
    var myMother = new Person("Sally", "Rally", 48, "green");
    
    document.getElementById("demo").innerHTML =
    "我的父亲年龄是 " + myFather.age + "。我的母亲年龄是 " + myMother.age; 
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <h2>JavaScript 对象</h2>
    
    <p>你无法给构造函数添加新的属性。</p>
    
    <p id="demo"></p>
    
    <script>
    function Person(first, last, age, eye) {
      this.firstName = first;
      this.lastName = last;
      this.age = age;
      this.eyeColor = eye;
    }
    
    Person.nationality = "English";
    
    var myFather = new Person("John", "Doe", 50, "blue");
    var myMother = new Person("Sally", "Rally", 48, "green");
    
    document.getElementById("demo").innerHTML =
    "我父亲的国籍是 " + myFather.nationality; 
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <h2>JavaScript 对象</h2>
    
    <p id="demo"></p>
    
    <script>
    function Person(first, last, age, eye) {
      this.firstName = first;
      this.lastName = last;
      this.age = age;
      this.eyeColor = eye;
      this.nationality = "English";
    }
    
    var myFather = new Person("John", "Doe", 50, "blue");
    var myMother = new Person("Sally", "Rally", 48, "green");
    
    document.getElementById("demo").innerHTML =
    "我父亲的国籍是 " + myFather.nationality + "。我母亲的国籍是 " + myMother.nationality;
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <h2>JavaScript 对象</h2>
    
    <p id="demo"></p>
    
    <script>
    function Person(first, last, age, eye) {
      this.firstName = first;
      this.lastName = last;
      this.age = age;
      this.eyeColor = eye;
    }
    
    Person.prototype.nationality = "English";
    
    var myFather = new Person("John", "Doe", 50, "blue");
    document.getElementById("demo").innerHTML =
    "我父亲对国籍是 " + myFather.nationality; 
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <h2>JavaScript 对象</h2>
    
    <p id="demo"></p>
    
    <script>
    function Person(first, last, age, eye) {
      this.firstName = first;
      this.lastName = last;
      this.age = age;
      this.eyeColor = eye;
    }
    
    Person.prototype.name = function() {
      return this.firstName + " " + this.lastName
    };
    
    var myFather = new Person("John", "Doe", 50, "blue");
    document.getElementById("demo").innerHTML =
    "我对父亲是 " + myFather.name(); 
    </script>
    
    </body>
    </html>

  • 相关阅读:
    location url 反向代理到来机的其它端口 gitlab
    PortSentry是入侵检测工具中配置最简单、效果最直接的工具之一
    iptables下state的4种形式
    windows  远程桌面命令 mstsc
    linux中解决SSH连接慢问题 关键点GSSAPIAuthentication
    无密码登录远程主机
    openfire 服务器名称:后面的黄色叹号
    ssh -v root@xxxxx 显示登录的细节
    mysql 只导数据不含表结构
    磁盘空间占满inode结点没用完 并删除了文件但是释放不了
  • 原文地址:https://www.cnblogs.com/tszr/p/10944468.html
Copyright © 2011-2022 走看看