修改原型对象的问题

            function Person(name,age){

                this.name=name;

                this.age=age;

                this.getName=function(){

                    console.log(this.name);

                }

            }

            Person.prototype.sayAge="hehe";

            var p = new Person("lucy","21");

            console.log(1,p instanceof Person);

            console.log(2,p.constructor === Person);

            console.log(3,p.hasOwnProperty('getAge'),p.sayAge);

            Person.prototype={

                getAge:function(){

                    alert(this.age);

                }

            }

            var d = new Person("lucy","21");

            console.log(1,d instanceof Person);

            console.log(2,d.constructor === Person);

            console.log(3,d.hasOwnProperty('getAge'),d.sayAge);

            

            

            

            如上,不知哪位能给出图形描述此题中原型链指向的情况~~~


至尊宝的传说
浏览 509回答 1
1回答

茅侃侃

打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript