How to convert anonymous function to regular?

Total JS noob here. I have the following line that implements jQuery Slider:

<script type="text/javascript">
    $(document).ready(function () {
        $("#wheelLeft").slider({ 
                 orientation: 'vertical', value: 37, 
                 min: -100, max: 100, 
                 slide: function (event, ui) { $("#lblInfo").text("left"); } });
    });
</script>

Mostly in an event slide, #lblInfogets its text in left. It works great. However, I would like to convert a built-in anonymous function that processes the slide event into a regular function.

Can anyone help?

+3
source share
4 answers
<script type="text/javascript">

function handleSlide(event, ui) { 
    $("#lblInfo").text("left"); 
}

$(document).ready(function () {
    $("#wheelLeft").slider({ 
             orientation: 'vertical', value: 37, 
             min: -100, max: 100, 
             slide: handleSlide
    });
});
</script>
+9
source
<script type="text/javascript">
    function myfunc(event, ui) {

    }

    $(document).ready(function () {
        myfunc(event, ui)
    });
</script>

would do that. This is obviously not an ideal solution as it still uses anonymous, but should solve any problems you have when you need to manually manipulate the function.

+2
source

:

function doSlide(event, ui)
{
    $("#lblInfo").text("left");
}

$(document).ready(function() {
    $("#wheelLeft").slider({
        orientation: 'vertical', value: 37, 
        min: -100, max: 100, 
        slide: doSlide
    });
});
+2
$(document).ready(function myFunction() {
    // do something
});
0

Source: https://habr.com/ru/post/1789092/


All Articles