iife and crockford-iife functions break
See original GitHub issueExamples:
// iife
(async () => {
await test()
})()
// crockford-iife
(async () => {
await test()
}())
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for your explain.
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):
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 thinkstest
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.