How does one create a function to call itself when a given condition is true in Mithril.js

Sujit :

This is my mithril code:

m('input', {
    id: 'someBox',
    placeholder: 'Type something',
    oninput: () => {
        query = document.getElementById('someBox).value;
        //do something

        for(var a=0; a<500; ++a) {
            if(query != document.getElementById('someBox'))
                //call this function

            //do a lot of something
        }
    }
})

Whenever someone inputs a text, a set or results are supposed to load. When the input changes, the results that are supposed to be loaded doesn't change unless the previous results finish loading. So to prevent this from happening I decided to have a condition inside the for() loop. Currently I am using a break; statement, but for some reason it doesn't load the results sometimes.

Is there any way to name this function?

Note: I cannot declare a function globally due to certain restrictions.

Yevgen Gorbunkov :

If that's not critical for you to use regular function (as opposed to arrow notation) attached to oninput property, you may refer to that function as this.oninput, like that:

m('input', {
    ...
    oninput: function(){
                ...
                if(query != document.getElementById('someBox'))
                //call this function
                this.oninput()
                ...
        }
    }
})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=220661&siteId=1