08JS高级 ——“继承”

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script type="text/javascript">
        function Father(name, age) {
            this.name = name;
            this.age = age;
        }
        Father.prototype.sayHi = function () {
            alert(this.name + "," + this.age);
        }

        function Son(name, age, gender) {
            this.gender = gender;
            Father.call(this, name, age); //继承“父类”的成员
        }
        Son.prototype = new Father();//Father.prototype;

        var f1 = new Father("张三", 30);
        f1.sayHi();

        var s1 = new Son("张三", "son", 1, true);

    </script>
</head>
<body>
</body>
</html>

 

08JS高级 ——“继承”,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。