How To call this inside event callback ? #503
-
Hi, i have inertia post. When event success called, i want call my function inside event callback. Here look :
But, i'm got error, myFunction undefined. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, This almost guaranteed has to do with the fact that the behaviour of
Since you are already using the arrow function syntax for your Hope this helps! If not, it would be appreciated if you could update your post with more relevant code of the context in which these functions exist, as the code you provided seems to be correct! |
Beta Was this translation helpful? Give feedback.
Hi,
This almost guaranteed has to do with the fact that the behaviour of
this
inside of an arrow function differs from the way a normal function is defined:this
variable refers to the object in which that function exists.this
variable refers to thethis
value in the parent scope.Since you are already using the arrow function syntax for your
onSuccess
callback,this
is referring to the scope in which yourInertia.post
was call is defined. It's likely that that scope, or one of the scopes surrounding that one, is a regular function, which is causingthis
to be 'rewritten', therefore losing the context that allows you to accessmyFunc…