原型繼承之constructor

        function Animal () {
            this.name = "Animal ";
        }this

        function Dog () {
            this.name = "Dog ";
        }prototype

        Dog.prototype = new Animal (); //此時B.prototype的構造器(B.prototype.constructor)變成了Animal io

        var dog = new Dog ();function

        //dog 的constructor爲Animal im

        //若是咱們要利用dog.constructor來作類型判斷,或者經過dog.constructor訪問Dog,必定要記得從新設置Dog.prototype.constructor = Dog;co

相關文章
相關標籤/搜索