您当前的位置: 首页 > 

暂无认证

  • 3浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

instanceof

发布时间:2020-09-11 12:34:44 ,浏览量:3

<!DOCTYPE html> <html> <head> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <script type="text/javascript"> /*
        1.什么是instanceof关键字?
        instanceof用于判断 "对象" 是否是指定构造函数的 "实例"
        */ /*
        2.instanceof注意点
        只要 构造函数的原型对象出现在实例对象的原型链中都会返回true
        意思是person的构造函数所指向的person原型对象出现在了student的原型链中就行了
        */ /*class Person
       {
       	    name="cyg";
       }
       let qq=new Person();
       console.log(qq instanceof Person);//qq实例是不是person构造函数所创建的实例对象
       class Cat{
            name = "mm";
        }
        let c = new Cat();
        console.log(c instanceof Person);*/ function Person(myName) { this.name = myName; } function Student(myName, myScore) { Person.call(this, myName); this.score = myScore; } Student.prototype = new Person(); Student.prototype.constructor = Student; let stu = new Student(); console.log(stu instanceof Person); // true </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.0478s