diff --git a/src/core/instance/state.js b/src/core/instance/state.js index b1549b0dcc4..ad56de7e90d 100644 --- a/src/core/instance/state.js +++ b/src/core/instance/state.js @@ -259,9 +259,9 @@ function initMethods (vm: Component, methods: Object) { const props = vm.$options.props for (const key in methods) { if (process.env.NODE_ENV !== 'production') { - if (methods[key] == null) { + if (typeof methods[key] !== 'function') { warn( - `Method "${key}" has an undefined value in the component definition. ` + + `Method "${key}" has type "${typeof methods[key]}" in the component definition. ` + `Did you reference the function correctly?`, vm ) @@ -279,7 +279,7 @@ function initMethods (vm: Component, methods: Object) { ) } } - vm[key] = methods[key] == null ? noop : bind(methods[key], vm) + vm[key] = typeof methods[key] !== 'function' ? noop : bind(methods[key], vm) } } diff --git a/test/unit/features/options/methods.spec.js b/test/unit/features/options/methods.spec.js index 34f9ee88fc6..f1e5fc68b27 100644 --- a/test/unit/features/options/methods.spec.js +++ b/test/unit/features/options/methods.spec.js @@ -19,13 +19,13 @@ describe('Options methods', () => { expect(vm.a).toBe(2) }) - it('should warn undefined methods', () => { + it('should warn methods of not function type', () => { new Vue({ methods: { - hello: undefined + hello: {} } }) - expect(`Method "hello" has an undefined value in the component definition`).toHaveBeenWarned() + expect('Method "hello" has type "object" in the component definition').toHaveBeenWarned() }) it('should warn methods conflicting with data', () => {