{"id":25,"date":"2014-01-07T12:18:00","date_gmt":"2014-01-07T12:18:00","guid":{"rendered":""},"modified":"2021-09-23T19:38:52","modified_gmt":"2021-09-23T17:38:52","slug":"iife","status":"publish","type":"post","link":"http:\/\/panahy.nl\/index.php\/2014\/01\/07\/iife\/","title":{"rendered":"IIFE"},"content":{"rendered":"<p>IIFE stands for: <b>Immediately-Invoked Function Expression<\/b><br \/>\nIt is a self-executing anonimous function like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">(function($){\r\n    $.fn.myplugin = funnction(options) {\r\n        var settings = {};\r\n        $.extend(settings, this.myPlugin.defaults, options);\r\n        return this;\r\n    };\r\n\r\n    $.fn.myPlugin.defaults = {\r\n        option1: 'option1',\r\n        option2: 'option2',\r\n        option3: 'option3'\r\n    };\r\n})(jQuery);<\/pre>\n<p>Another good example<\/p>\n<p><code><\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\/\/ Create an anonymous function expression that gets invoked immediately,\r\n\/\/ and assign its *return value* to a variable. This approach \"cuts out the\r\n\/\/ middleman\" of the named `makeWhatever` function reference.\r\n\/\/\r\n\/\/ As explained in the above \"important note,\" even though parens are not\r\n\/\/ required around this function expression, they should still be used as a\r\n\/\/ matter of convention to help clarify that the variable is being set to\r\n\/\/ the function's *result* and not the function itself.\r\n\r\nvar counter = (function(){\r\n  var i = 0;\r\n\r\n  return {\r\n    get: function(){\r\n      return i;\r\n    },\r\n    set: function( val ){\r\n      i = val;\r\n    },\r\n    increment: function() {\r\n      return ++i;\r\n    }\r\n  };\r\n}());\r\n\r\n\/\/ `counter` is an object with properties, which in this case happen to be\r\n\/\/ methods.\r\n\r\ncounter.get(); \/\/ 0\r\ncounter.set( 3 );\r\ncounter.increment(); \/\/ 4\r\ncounter.increment(); \/\/ 5\r\n\r\ncounter.i; \/\/ undefined (`i` is not a property of the returned object)\r\ni; \/\/ ReferenceError: i is not defined (it only exists inside the closure)\r\n<\/pre>\n<p><code><\/code><\/p>\n<p>Source: http:\/\/benalman.com\/news\/2010\/11\/immediately-invoked-function-expression\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>IIFE stands for: Immediately-Invoked Function Expression It is a self-executing anonimous function like this: (function($){ $.fn.myplugin = funnction(options) { var settings = {}; $.extend(settings, this.myPlugin.defaults, options); return this; }; $.fn.myPlugin.defaults = { option1: &#8216;option1&#8217;, option2: &#8216;option2&#8217;, option3: &#8216;option3&#8217; }; })(jQuery); Another good example \/\/ Create an anonymous function expression that gets invoked immediately, \/\/ and &hellip; <a href=\"http:\/\/panahy.nl\/index.php\/2014\/01\/07\/iife\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;IIFE&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Pouya Panahy","author_link":"http:\/\/panahy.nl\/index.php\/author\/pouya\/"},"uagb_comment_info":0,"uagb_excerpt":"IIFE stands for: Immediately-Invoked Function Expression It is a self-executing anonimous function like this: (function($){ $.fn.myplugin = funnction(options) { var settings = {}; $.extend(settings, this.myPlugin.defaults, options); return this; }; $.fn.myPlugin.defaults = { option1: 'option1', option2: 'option2', option3: 'option3' }; })(jQuery); Another good example \/\/ Create an anonymous function expression that gets invoked immediately, \/\/ and&hellip;","_links":{"self":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/25"}],"collection":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":3,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":195,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/25\/revisions\/195"}],"wp:attachment":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}