• JavaScript学习----Prototype


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>JavaScript Study 2015.11.9--</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">  
    
        </style>
        
        <script type="text/javascript">
        //prototype的内存分析
        
        /*
        //第1种状态
        function Person(name,age){
            this.name = name;
            this.age = age;
            this.say = function(){
                alert(this.name+","+this.age);
            }
        }
        
        //第2种状态
        Person.prototype.sayHi = function(){
           alert(this.name+":sayHi");
        }
        //第3种状态
        var p1 = new Person("lili",20);
        
        //第4种状态
        p1.say();
        */
        
        
        //prototype重写的内存分析
        
        //第1种状态
        function Person(name,age){
            this.name = name;
            this.age = age;
            this.say = function(){
                alert(this.name+","+this.age);
            }
        }
        //第2种状态
        var p1 = new Person("lili",20);
        
        //第3种状态
        Person.prototype = {
             sayHi:function(){
               alert("sayHi");
             }
        }
        //第4种状态
        var p2 = new Person("disk",30);
        
        p1.say();//no error
        p2.say();//no error
        
        //p1.sayHi();//error
        p2.sayHi();//no error
        
    
    
        </script>
      </head>
      <body>
        <div id="wrap">
          
        </div>
      </body>
    </html>
  • 相关阅读:
    SQL Server 通用分页存储过程
    SQL 分页通用存储过程
    python 获取本机IP的三种方式
    Python代码打印出9*9 九九乘法表
    python进程.线程和协程的总结
    5.__魔法方法__开会喽
    css干货部分
    html干货部分
    pyinstaller 打包exe可执行文件
    3_3.黏包现象
  • 原文地址:https://www.cnblogs.com/heavyhe/p/4981297.html
Copyright © 2020-2023  润新知