• JavaScript面向对象之类的继承


    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>JavaScript中的继承</title>
    
    <script type="text/javascript">
    // 父类
    function Person(name,email){   // 父类的构造方法
    	this.name = name ;
    	this.email = email ;
    }
    
    Person.prototype.getInfo = function(){
    	return this.name+"的Email是:"+this.email ;
    }
    
    // 子类
    
    function Employee(name,email,title){
    	// 如同高级程序语言中的super()方法,调用父类的构造方法,但必须传入scope为子类对象的实例
    	Person.call(this,name,email) ;
    	// 子类特色的属性
    	this.title = title ;
    }
    // 假设要继承Person,子类的prototype必须指定父类的实例
    
    Employee.prototype = new Person () ;
    
    var emp = new Employee('1212','11222@qq.com','title1234');
    
    //  假设没有明白支持子类使用构造方法为父类的构造方法 
    console.info(Employee.prototype);
    
    console.info(emp.getInfo());
    
    delete Employee.prototype.name ;   // 假设子类不须要父类的属性能够通过delete进行删除
    //  假设子类和父类的构造方法处理事情不同能够明白的指出用子类的构造方法
    Employee.prototype.constructor = Employee ;
    
    console.info(Employee.prototype.constructor) ;
    </script>
    
    
    </head>
    
    <body>
    </body>
    </html>
    

  • 相关阅读:
    java09 队列Queue与Deque
    java08 Set
    java07 map
    SNMP学习
    NPM
    windows主机资源Snmp OIDs CPU, Memory, Disk等
    servlet3.0 @webfilter 过滤顺序
    snmp v3的安全配置 snmp认证与加密配置(53)
    CentOS 7.2 (mini) 里iptables防火墙怎么关闭?
    ORA-00845 MEMORY_TARGET not supported on this system 的解决
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/7308627.html
Copyright © 2020-2023  润新知