• JavaScript面向对象技术


     最近在研究JavaScript面向对象方面的技术,偶然之间使用了下面这种方法来实现继承.
    在IE6和IE7的测试,结果都能正确实现继承.
    可我在网上却找不到有这样的做法,是不是这样做有什么不妥,还请高人指点!

    重点是这句:Employee.prototype = Person.prototype

            function Person(name){
            
                
    this.name = name;
                
            }

            
            Person.prototype 
    = {
            
                say : 
    function(){
                
                        alert(
    this.name);
                    }

            }

            
            
            
    function Employee(name, salary){
            
                Person.call(
    this, name);
                
    this.salary = salary;
            
            }

            
            
    //请问这句会有什么问题
            Employee.prototype = Person.prototype;
            
            Employee.prototype.showMeTheMoney 
    = function(){
                
                alert(
    "name: " + this.name + ", salary: " + this.salary);
            }

            
            
    var BillGates = new Person("Bill Gates");
            
    var SteveJobs = new Employee("Steve Jobs"1);
                   
            
            BillGates.say();
            SteveJobs.say();
            SteveJobs.showMeTheMoney();
            
            
            alert(BillGates.say 
    == SteveJobs.say);
  • 相关阅读:
    jQuery.messager 使用
    对应后台传json ajax 获取值判断
    easyui datagrid nowrap 使用方法
    easyui combogrid setValues
    去除字符串中所有的逗号
    datagrid loadData 使用方法
    使用git下载一个项目
    java中读取文本文件的时候@Test方法中没有中文乱码,但是@Controller中却有中文乱码
    IDEA启动项目的时候,控制台中显示的都是乱码
    微信流量主点击量与曝光量是什么意思
  • 原文地址:https://www.cnblogs.com/oxsir/p/1203502.html
Copyright © 2020-2023  润新知