vue高级问题JavaScript原型问题

#在一个.vue文件中

import Vue from 'vue';
//生命周期
created() {
    console.log(Vue === this.__proto__.constructor);
    //为什么是false, 难道this不是new Vue()得到的吗
    //毫无疑问, Vue是一个构造函数, 难道this不是Vue的实例 ?
  }

实例是 new Vue 得到的?


this instanceof Vue //true
this.__proto__.constructor=== Vue // false 打印得知this.__proto__.constructor 是VueComponent不是Vue,但是继承自Vue

打印一下,看到区别。vueComponent是继承过来的,原型指向vue,构造函数指向自己

img

你换个生命周期试试

看我博客的数据类型详解你就懂了,至少也有收获