您当前的位置: 首页 > 

暂无认证

  • 3浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

isPrototypeOf详解

发布时间:2020-09-11 19:30:13 ,浏览量:3

/*
        1.什么是isPrototypeOf属性
        isPrototypeOf用于判断 一个对象是否是另一个对象的原型
        */ /*
        2.isPrototypeOf注意点
        2.1只要调用者在传入对象的原型链上都会返回true
        */ <!DOCTYPE html> <html> <head> <title></title> </head> <body> <script type="text/javascript"> /*
        1.什么是isPrototypeOf属性
        isPrototypeOf用于判断 一个对象是否是另一个对象的原型
        */ /*
        2.isPrototypeOf注意点
        2.1只要调用者在传入对象的原型链上都会返回true
        */ /*class Person
       {
       		name="cyg";
       }
       let p=new Person();
       console.log(Person.prototype.isPrototypeOf(p));
       //判断p对象的原型链中是否存在person。就会返回true。否则false。
        class Cat{
            name = "mm";
        }
        console.log(Cat.prototype.isPrototypeOf(p));
        */ function Person(myName) { this.name = myName; } function Student(myName, myScore) { Person.call(this, myName);//第一步通过call把person类改成student。 this.score = myScore; } //第二步再修改student的原型对象为new Person(); Student.prototype = new Person(); //并把Student.prototype.constructor指向了student的构造函数。 Student.prototype.constructor = Student; let stu = new Student(); console.log(Person.prototype.isPrototypeOf(stu)); // true </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.0726s