zoukankan      html  css  js  c++  java
  • prototype

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <!--使用 prototype 属性可以向对象添加属性:-->
    <script type="text/javascript">
    
        function employee(name,job,born)
        {
            this.name=name;
            this.job=job;
            this.born=born;
        }
    
        var bill=new employee("Bill Gates","Engineer",1985);
    
        employee.prototype.salary=null;
        bill.salary=20000;
    
        employee.prototype = {
            testProperty:"zhangjie"
        }/*这样做不会删除原来的属性,原因在于prototype只是用来添加属性的,并不会删除属性*/
        var newOne = new employee();
        document.write(bill.salary);/*正常显示2000*/
        document.write(bill.testProperty); /*undefined*/ /*testProperty属性是在bill之后才设定的,*/
        document.write(newOne.name);/*undefined未定义*/
        document.write(newOne.testProperty);/*zhangjie*/ /*正常显示*/
    </script>
    </body>
    </html>
  • 相关阅读:
    java 构建一个简单的菜单
    java JSplitPane
    java 使用ActionListener监控
    java 显示单选按钮
    工作 激情
    明天会更好
    记录
    现在
    嘿嘿
    书籍 知识
  • 原文地址:https://www.cnblogs.com/foreverlin/p/10095836.html
Copyright © 2011-2022 走看看