question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iife and crockford-iife functions break

See original GitHub issue

Examples:

// iife
(async () => {

  await test()

})()
// crockford-iife
(async () => {

  await test()

}())

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
fundoncommented, Oct 6, 2016

Thank you for your explain.

0reactions
leebyroncommented, Oct 6, 2016

That error is expected given that code (though node could be more helpful with its errors).

You can test this by trying the same thing using node without the async/await (not using this library at all):

const test = {
  run () {
  }
}

(() => {
  test.run()
})()
iife.js:6
(() => {
^

TypeError: (intermediate value) is not a function

This is because of Automatic Semicolon Insertion (a good resource: https://github.com/getify/You-Dont-Know-JS/blob/master/types %26 grammar/ch5.md#automatic-semicolons)

This is because any expression followed by () assumes that you mean the previous expression is a function to be called. In this case: const test = {run(){}}(()=>{test.run()}) JavaScript thinks test will be assigned the result of a function call where {run(){}} is the “intermediate value” function to call and ()=>{test.run()} is the argument to the function.

Check out https://astexplorer.net/#/efPw48Ufoh to see how JavaScript parses this.

The fix is to ensure there’s a semicolon somewhere before your IIFE.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disassembling JavaScript's IIFE Syntax - Marius Schulz
This post inspects the syntax of an immediately invoked function expression (or IIFE) in JavaScript and presents some variations of it.
Read more >
06 Immediately-Invoked Function Expressions (IIFE)
Animmediately-invoked function expression(IIFE) is a function that is called immediately after it is defined. Utilizing an IIFE alongside closures allows for ...
Read more >
iife - What is the (function() { } )() construct in JavaScript?
This is an Immediately Invoked Function Expression in Javascript: To understand IIFE in JS, lets break it down: Expression: Something that returns a...
Read more >
IIFE, Function Parameters, and Code Blocks Explained
A JavaScript function is an executable piece of code developers use to bundle a block of zero or more statements. In other words,...
Read more >
Appendix A. JavaScript Style Guide
The test() function lets you name and define individual module tests. ... is called an Immediately Invoked Function Expression (IIFE, pronounced “iffy”).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found