mardi 29 novembre 2016

Is this an IIFE?

I'm trying to understand how this JavaScript code works. It's a library to help make multi-step modals. It relies on Bootstrap and jQuery. (Full code on github)

This is a very stripped down version that shows the basic outline:

function multistep($) {
    'use strict';

    var modals = $('.modal.multi-step');
    modals.each(function (idx, modal) {
        //variables set
        //many other functions

        function initialize() {            
            //code...
        }
        initialize();
    })
} (jQuery);

This is how it's called on the HTML page:

<script type="text/javascript">

    $(function () {
        multistep(jQuery);
    })

</script>

I would have thought that the (jQuery) following the function multistep($) declaration means that multistep is an IIFE, but:

  1. There are no parentheses around the entire function
  2. The function has to be called in the document.ready, and doesn't execute automatically

What pattern does this code follow? What am I missing?

Aucun commentaire:

Enregistrer un commentaire