zoukankan      html  css  js  c++  java
  • JavaScript的prototype的属性和方法使用

    function Person(name, sex) {
        this.name = name;
        this.sex = sex;
    }
    Person.prototype = {
        getName: function () {
            return this.name;
        },
        getSex: function () {
            return this.sex;
        }
    }
    Person.prototype.age = 25;
    var zhang = new Person("ZhangSan", "man");
    var chun = new Person("ChunHua", "woman");
    
    function Employee(name, sex, employeeID) {
        this.name = name;
        this.sex = sex;
        this.employeeID = employeeID;
    }
    
    function ShowCase() {
            alert(zhang.getName());
            alert(chun.getName());
            alert(zhang.age);
            alert(chun.age);
    
            
            Employee.prototype = new Person('vf','sf');
            Employee.prototype.getEmployeeID = function () {
                return this.employeeID;
            };
            var wa = new Employee("wawu", "man", "1234");
            alert(wa.getName());
            alert(wa.getEmployeeID());
            
        }
  • 相关阅读:
    React之React.cloneElement
    HTB-靶机-Vault
    HTB-靶机-Curling
    HTB-靶机-Zipper
    HTB-靶机-Frolic
    HTB-靶机-Carrier
    HTB-靶机-Oz
    HTB-靶机-Dab
    HTB-靶机-Waldo
    HTB-靶机-Reddish
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2659887.html
Copyright © 2011-2022 走看看