JavaScript – Passing a Function to a Function

On the example of the usual exporting functions to JS and a section of code on Svelte.

File 1: JS file of exported functions

let time out = null;
export function updateWait(item, updateNote) {
clearTimeout(timeout);

timeout = setTimeout(function () {
updateNote(item);
}, 1000);
}

File 2: Svelte

– First we import the function.
– Then the main function, which we will further transfer to the imported function.
– And at the very bottom, we call the imported function and pass parameters there: one of the parameters is the second function.

<script>
import {updateWait} from ‘../../assets/js/universal’;

function updateOperation(operation) {
let data = {
‘id_’: operation.id,
‘note’: operation.note
}

patchFetch(‘update/’, data);
}
script>

<textarea rows=“2”
bind:value=“{operation.note}”
on:key down=“{handle}”
on:paste=“{handle}”
on:input=“{()=> updateWait(operation, updateOperation)}”
>textarea>

The site has no goal of self-sustaining, so there are no ads on the site. But if the information was useful to you, you can like the page, leave a comment, or send me a gift for a cup of coffee.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *