From 09c5137045fcf4045c2012b1332ff242997ba870 Mon Sep 17 00:00:00 2001 From: An Phan Date: Fri, 6 Oct 2017 16:29:40 +0100 Subject: [PATCH 1/2] Make the statement less definitive --- src/v2/guide/instance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v2/guide/instance.md b/src/v2/guide/instance.md index 799883f7ce..eab1e2587a 100644 --- a/src/v2/guide/instance.md +++ b/src/v2/guide/instance.md @@ -118,7 +118,7 @@ new Vue({ There are also other hooks which will be called at different stages of the instance's lifecycle, such as [`mounted`](../api/#mounted), [`updated`](../api/#updated), and [`destroyed`](../api/#destroyed). All lifecycle hooks are called with their `this` context pointing to the Vue instance invoking it. -

Don't use [arrow functions](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) on an options property or callback, such as `created: () => console.log(this.a)` or `vm.$watch('a', newValue => this.myMethod())`. Since arrow functions are bound to the parent context, `this` will not be the Vue instance as you'd expect and `this.a` or `this.myMethod` will be undefined.

+

Don't use [arrow functions](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) on an options property or callback, such as `created: () => console.log(this.a)` or `vm.$watch('a', newValue => this.myMethod())`. Since arrow functions are bound to the parent context, `this` will not be the Vue instance as you'd expect and it's very likely that `this.a` or `this.myMethod` will be undefined.

## Lifecycle Diagram From b11dc80705787be2d978d3f4a447107bd56c73a4 Mon Sep 17 00:00:00 2001 From: An Phan Date: Sat, 7 Oct 2017 19:39:32 +0100 Subject: [PATCH 2/2] Reword the tip --- src/v2/guide/instance.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/v2/guide/instance.md b/src/v2/guide/instance.md index eab1e2587a..94ee82319c 100644 --- a/src/v2/guide/instance.md +++ b/src/v2/guide/instance.md @@ -118,7 +118,8 @@ new Vue({ There are also other hooks which will be called at different stages of the instance's lifecycle, such as [`mounted`](../api/#mounted), [`updated`](../api/#updated), and [`destroyed`](../api/#destroyed). All lifecycle hooks are called with their `this` context pointing to the Vue instance invoking it. -

Don't use [arrow functions](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) on an options property or callback, such as `created: () => console.log(this.a)` or `vm.$watch('a', newValue => this.myMethod())`. Since arrow functions are bound to the parent context, `this` will not be the Vue instance as you'd expect and it's very likely that `this.a` or `this.myMethod` will be undefined.

+

Don't use [arrow functions](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) on an options property or callback, such as `created: () => console.log(this.a)` or `vm.$watch('a', newValue => this.myMethod())`. Since arrow functions are bound to the parent context, `this` will not be the Vue instance as you'd expect, often resulting in errors such as `Uncaught TypeError: Cannot read property of undefined` or `Uncaught TypeError: this.myMethod is not a function`.

+ ## Lifecycle Diagram