前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >instanceof

instanceof

作者头像
贵哥的编程之路
发布2020-10-28 10:41:55
4730
发布2020-10-28 10:41:55
举报
文章被收录于专栏:用户7873631的专栏
代码语言:javascript
复制
<!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>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/09/11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档