Access Component Object in External Callback?

2019-08-28 23:42发布

问题:

In the following code, in which submit is a method in an external JavaScript module, is it possible for submit() to access the component object?

Component.html

<button on:click={submit}>Submit</button>

<script>
    import { submit } from './';
</script>

index.js

export function submit()
{
    console.log(this); // <button>Submit</button>
};

Before Svelte 3, this would be the component object, but in Svelte 3, this seems to be the target element.