0
     (function(obj){
        $.each(Templates.inputs, function(key, value){
            obj.elementsKey.push(key);
            obj.elementsValueType.push(value.type);
        });
     }(this));

why is this (this)) used after function? And What does obj does when used as parameter

  • `this`-the context is passed the the IIFE. Two reasons: **1.** `this` inside `each()` refers to the current element in the set **2.** Less scope-chaingin traversing. – Tushar Aug 04 '16 at 10:48

1 Answers1

0

This is so-called IIFE - you declare a function and immediatly calling it. This function has argument obj, in which current variable this is placed. So, for example, if you run this IIFE inside a global scope, you'll get a window object in a obj variable inside function.

More about IIFE