User Tools

Site Tools


snippets:iife

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
snippets:iife [2018/03/20 11:20] – created allsparksnippets:iife [2018/03/20 11:24] (current) – [go] allspark
Line 1: Line 1:
 +# Immediately-invoked Function Expression
  
 +## c++
 +
 +```cpp
 +#include <iostream>
 +
 +int main() {
 +  [](int v) {
 +    std::cout << v << std::endl;
 +  }(42);
 +  
 +  return 0;
 +}
 +```
 +
 +## go
 +
 +```go
 +package main
 +
 +import "fmt"
 +
 +func main() {
 +  func (v int) {
 +    fmt.Println(v)
 +  }(42);
 +}
 +```
 +
 +## javascript
 +
 +```javascript
 +(function (v) {
 +  console.log(v);
 +})(42);
 +```