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>
  • 相关阅读:
    工厂方法
    简单工厂
    单例模式
    MVC中Cookies的简单读写操作
    windows服务开启(收藏url)
    WCF的三种模式
    SvcUtil.exe导入WCF
    简述wcf应用
    sql的几种常用锁简述
    Lucene.Net和盘古分词应用
  • 原文地址:https://www.cnblogs.com/foreverlin/p/10095836.html
Copyright © 2011-2022 走看看