码迷,mamicode.com
首页 > Web开发 > 详细

08JS高级 ——“继承”

时间:2014-06-14 08:57:40      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

<!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高级 ——“继承”,布布扣,bubuko.com

08JS高级 ——“继承”

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/sumg/p/3787789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!