vm.$options 问题
来源:3-3 patch(上)

六一888
2019-12-30
export function initInternalComponent (vm: Component, options: InternalComponentOptions) {
const opts = vm.$options = Object.create(vm.constructor.options)
console.log(vm)
// doing this because it's faster than dynamic enumeration.
...
}
这段代码中,为什么要使用 Object.create 方法?直接赋值不可以么?为什么要赋值给 vm.$options 的原型对象 Object。
写回答
1回答
-
因为需要创建一个新的对象引用,直接赋值会导致你对 vm.$options 的操作可能会影响 vm.constructor.options 原对象。
012019-12-31
相似问题