Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using class method breaks inheritance #28

Closed
ggedde opened this issue Mar 9, 2020 · 4 comments
Closed

Using class method breaks inheritance #28

ggedde opened this issue Mar 9, 2020 · 4 comments
Labels
more info needed ❓ Further information is requested

Comments

@ggedde
Copy link

ggedde commented Mar 9, 2020

When using v-debounce="myClass.action"
I get an error that within my class that "this" is undefined.

Here is an example of my class:

class myClass {
	data = {
		name: 'Testing'
	};

	constructor() {
		console.log(this.data);
	}

	public action() {
		console.log(this.data);
	}
}

When the class initializes I get the console log of "{name: Testing}"

But when I Type into my field I get the following response:
Uncaught TypeError: Cannot read property 'data' of undefined

So I am curious if v-debounce is overriding the Class inheritance or something. Or possibly I am not coding this correctly :)

Any help would be appreciated.
Thanks

@ggedde
Copy link
Author

ggedde commented Mar 10, 2020

I was able to resolve by changing my class to a Static class, but that required a bunch of rework. So it seems just instance based classes have conflicts with "this".

@dhershman1
Copy link
Owner

I want to say that vue debounce shouldn't be directly affecting your inheritance but I don't want to dismiss it either.

What the lib does is wraps the function you give me into a handler that is then used for event listeners. None of these are arrow functions so that may be where you lose your scope.

Do you mind sending me a full example of some code you ran into this problem with, as I don't use classes I am unsure of where this might be setup/used.

@dhershman1 dhershman1 added the more info needed ❓ Further information is requested label Mar 10, 2020
@dhershman1 dhershman1 mentioned this issue Mar 27, 2020
@dhershman1
Copy link
Owner

I'm hoping #31 may have addressed this issue, so I'm closing it for now feel free to re open if needed.

@ggedde
Copy link
Author

ggedde commented Mar 27, 2020

Ok thanks. I will try and test it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed ❓ Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants