Development/JavaScript

javascript - IIFE, Module

linuxism 2018. 1. 2. 21:21


* Case 1

(function(window, $) {

var someVar = true;

var test = {

                some: 'test',

setValue: function() {

                    // some code

}

};

window.test = test;

})(window, jQuery);


* Case 2

var test = (function(test, $, undefined) {

    var someVar = true;

    test.some = 'test';

    test.setValue = function() {

        // some code

    }

    return test;

}(window.test || {}, jQuery));