diff --git a/src/core/observer/array.js b/src/core/observer/array.js index 684e37ece58..2f0f712097b 100644 --- a/src/core/observer/array.js +++ b/src/core/observer/array.js @@ -8,7 +8,7 @@ import { def } from '../util/index' const arrayProto = Array.prototype export const arrayMethods = Object.create(arrayProto) -const methodsToPatch = [ +export const methodsToPatch = [ 'push', 'pop', 'shift', diff --git a/src/core/observer/index.js b/src/core/observer/index.js index 4a030ed7f99..3a635d68073 100644 --- a/src/core/observer/index.js +++ b/src/core/observer/index.js @@ -2,7 +2,7 @@ import Dep from './dep' import VNode from '../vdom/vnode' -import { arrayMethods } from './array' +import { arrayMethods, methodsToPatch } from './array' import { def, warn, @@ -16,8 +16,6 @@ import { isServerRendering } from '../util/index' -const arrayKeys = Object.getOwnPropertyNames(arrayMethods) - /** * In some cases we may want to disable observation inside a component's * update computation. @@ -48,7 +46,12 @@ export class Observer { const augment = hasProto ? protoAugment : copyAugment - augment(value, arrayMethods, arrayKeys) + + const methods = Object.create(value.constructor.prototype) + methodsToPatch.forEach((m) => { + if (methods[m]) methods[m] = arrayMethods[m] + }) + augment(value, methods, Object.getOwnPropertyNames(methods)) this.observeArray(value) } else { this.walk(value)