面试题

作者: asimpleday | 来源:发表于2019-01-17 20:23 被阅读0次
    1、继承、原型、面向对象
    function Parent() {
        this.a = 1;
        this.b = [1, 2, this.a];
        this.c = { demo: 5 };
        this.show = function () {
            console.log(this.a , this.b , this.c.demo );
        }
    }
    function Child() {
        this.a = 2;
        this.change = function () {
            this.b.push(this.a);
            this.a = this.b.length;
            this.c.demo = this.a++;
        }
    }
    Child.prototype = new Parent();
    var parent = new Parent();
    var child1 = new Child();
    var child2 = new Child();
    child1.a = 11;
    child2.a = 12;
    parent.show();
    child1.show();
    child2.show();
    child1.change();
    child2.change();
    parent.show();
    child1.show();
    child2.show();
    

    相关文章

      网友评论

          本文标题:面试题

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