构造继承

作者: 杰克_王_ | 来源:发表于2019-10-20 14:12 被阅读0次
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>构造继承</title>
</head>

<body>
    <script>
        /*
        call 是以对象列表的方式进行传参
        apply 使用数组的方式进行传参
        */
        /*
        不能继承原型方法
        */

        function Animal(category) {
            this.category = category || "Animal";
            this.run = function () {
                console.log("Animal run");
            }
        }

        Animal.prototype.walk = function () {
            console.log("Animal walk");
        }

        function Dog(category, name) {
            Animal.call(this, category);
            // Animal.apply(this, [category]);
            this.name = name || 'dog';
            this.type = 'dog';
        }

        var dog = new Dog("dog", "小白");
        console.log(dog);
    </script>
</body>

</html>

相关文章

  • Javascript如何实现继承

    构造函数继承 原型构造函数组合继承

  • js基础之实现继承的几种方式

    js 实现继承的方式有: 原型链继承; 构造函数继承; 组合继承(原型链继承 + 构造函数继承)(最常用);(原型...

  • JavaScript的六种继承方式

    JavaScript的几种继承方式 原型链继承 借助构造函数继承(经典继承) 组合继承:原型链 + 借用构造函数(...

  • js继承方式

    类式继承 构造函数继承 组合继承 类式继承 + 构造函数继承 原型式继承 寄生式继承 寄生组合式继承 寄生式继承 ...

  • 三种常见继承

    1.原型继承 2.构造继承 对比 构造函数继承的方法类似于复制,消耗内存 构造函数继承的方法不能改变,而原型继承可...

  • 构造继承

  • 前端面试题总结【38】:javascript继承的 6 种方法

    原型链继承 借用构造函数继承 组合继承(原型+借用构造) 原型式继承 寄生式继承 寄生组合式继承 推荐: 持续更新...

  • js的继承方式

    1 类式继承 子类的原型对象 2 构造函数继承 创建即继承 3 组合继承 (类式继承和构造函数...

  • js继承简单介绍

    一.构造继承 构造函数继承: function Super(){ this.colors= ['c','a','b...

  • js的继承方式

    js的继承方式 一、原型链继承 原型继承的缺点: 二. 构造函数继承 构造函数继承的缺点: 三. 组合式继承 组合...

网友评论

    本文标题:构造继承

    本文链接:https://www.haomeiwen.com/subject/wmtamctx.html