iife Questions

3

Solved

I want to write several constants for my Angular JS app. I want to write them in a separate file and want to access them. I have tried with IIFE (Immediately Invoked Function Expression) like this...
Viens asked 11/7, 2017 at 13:36

1

Solved

I'm trying to rollup my completely es6 module repo which has both local imports/export for the projects, and imports to dependencies that are also either scripts or modules. I'm also trying to hav...
Disaccharide asked 13/6, 2017 at 4:12

1

I'm currently reading Greg Franko's blog article on 'jQuery Best Practices'. Among his early slides, he explains the typical/better/best ways of doing things. Typical (link) $("document").ready(...
Nevil asked 18/4, 2017 at 21:6

4

Solved

I was recently comparing the current version of json2.js with the version I had in my project and noticed a difference in how the function expression was created and self executed. The code used t...
Lusatian asked 2/8, 2010 at 1:39

3

Solved

Both of the following code snippets worked: Using IIFE in js file: (function initialize() { txtInput = document.getElementById('txtInput'); txtResult = document.getElementById('txtResult'); txt...
Crucible asked 20/3, 2014 at 15:10

5

Solved

What is the difference between these two: $(function () { // do stuff }); AND (function () { // do stuff })();
Dygert asked 30/9, 2011 at 18:31

1

Solved

How to using ES6 Arrow function to realize IIFEImmediately-Invoked Function Expression? Here is my demo codes, and it had tested passed! // ES 6 + IIFE (() => { let b = false; c...

1

Solved

I'm used to programming in javascript where I can do the following to pass an argument into an immediately-invoked function expression: (function(twoSeconds) { // do something with "twoSeconds" h...
Paulinapauline asked 17/10, 2016 at 8:47

4

Apparently, ES6 doesn't need namespacing because each file is a separate module. But then, how do I avoid global namespace interference? For example, Babel compiles my scripts/main.js file by mer...
Ogawa asked 23/9, 2015 at 18:11

4

Solved

While reviewing some of the code written in the Twitter Bootstrap Javascript, it looks like they're calling immediately invoked anonymous functions like this: !function( $ ) { ... }(window.jQue...
Campground asked 29/11, 2011 at 4:38

1

Solved

I've seen IIFE's written: (function() { console.log("do cool stuff"); })(); as well as: (function() { console.log("do more cool stuff"); }()); They seem to work the same in any context I'...
Distinguishing asked 5/7, 2016 at 3:56

2

Solved

In ES5, writing such code has been considered as good practice: (function () { //some magic })(); But in ES6 variables created with let keyword are not attached to window object. So, is there ...
Maupassant asked 23/5, 2016 at 19:45

1

Solved

Say, for example, I need to register an onclick event that calls another function sayHello() to say hello, with its parameter as a variable available in the current scope. I could use IIFE to inje...
Hickson asked 20/4, 2016 at 14:36

2

Solved

Recently while I was trying to learn more about IIFE and modules in JavaScript a question came to my mind that how is IIFE making a Module while not Immediately Invoking the function doesn't make i...
Cumquat asked 6/2, 2016 at 5:37

2

Solved

I have started reading this book. Chapter 2 says that there are different ways to write an IIFE: !function (){}() ~function (){}() +function (){}() -function (){}() new function (){} 1,functio...
Dyan asked 11/11, 2015 at 13:7

2

Solved

In Javascript, an IIFE (Immediately-Invoked Function Expression, though there may be other expansions of the acronym) can be written as: (function () { var foo = 'bar' console.log('hi!'); })(); ...
Emera asked 4/11, 2015 at 13:57

0

Friday I spent some time refactoring an AngularJS application that I've been working on for the last few weeks. My refactoring centered on 4 pretty specific areas: wrapping all of my Angula...
Porcupine asked 26/9, 2015 at 15:45

4

Solved

I am looking at a piece of code: (function($) { // other code here $(document).ready(function() { // other code here }); })(jQuery); I though the IIFE does the functions of $(document)....
Carycaryatid asked 24/7, 2014 at 10:4

3

Solved

I'm reading up on JavaScript IIFE and so far the understand concept, but I am wondering about the outside parenthesis. Specifically, why are they required? For example, (function() {var msg=...
Pornography asked 10/8, 2015 at 0:45

1

The common practise for creating modules is to wrap them in parens so you won't leak any variables outside of the module (when concatenating etc). There is also void operator, which evaluates a g...
Suppurative asked 3/3, 2015 at 9:35

6

Solved

I'm studying THREE.js and noticed a pattern where functions are defined like so: var foo = ( function () { var bar = new Bar(); return function ( ) { //actual logic using bar from above. //re...
Crotch asked 29/9, 2014 at 3:27

2

Solved

I've specified a function in my controller like this: $scope.myFunction = function(){ console.log('test'); } I want this function to be triggered when a selectbox has been changed. Therefore I a...
Colp asked 3/9, 2014 at 12:57

1

Solved

I have an angular app that has a lot of .js files. It's boring to add an IIFE to each file and then add 'use strict'. Is there any way to automate this? I use gulp to run tasks.
Lipcombe asked 26/8, 2014 at 14:31

1

Solved

I see this syntax everywhere: var mod = (function(){ var pvtvar; var pvtfunc = function(){}; //return an object literal return { pubvar : 'whatever', pubfunc : function(){} }; }()); I re...
Dumbarton asked 27/7, 2014 at 3:59

7

Solved

When you wrap your JavaScript code in a function like this: (function(){ var field = ...; function doSomthing(){... ... })(); I noticed that this fixes scoping problems for me on a lot of ...
Harrisonharrod asked 15/9, 2010 at 17:48

© 2022 - 2024 — McMap. All rights reserved.