1

What does () sign mean in this nested Record using immutable.js?

This is the code:

'use strict'

const {Record} = require('immutable')

const Form = Record({
  disabled: false,
  fields: new (Record({
    username: '',
    usernameHasError: false,
    email: '',
    emailHasError: false,
    password: '',
    passwordHasError: false,
    passwordAgain: '',
    passwordAgainHasError: false,
    showPassword: false
  }))()
})

At the the of the fields there is extra () sign, what does it mean? What syntax is it?

Tom Kur
  • 1,530
  • 1
  • 13
  • 21
  • `()` is the syntax to call a function without passing any parameters. – 4castle Sep 03 '18 at 10:44
  • In the code case, why is there a function? shouldnt it contain only state record? – Tom Kur Sep 03 '18 at 10:49
  • [`Record`](https://facebook.github.io/immutable-js/docs/#/Record) returns a function which is being immediately invoked by the `new (....)()` syntax – 4castle Sep 03 '18 at 10:55

1 Answers1

0

This an immediately invoking function expression(IIFE). Such function will be be immediately executed.

When a function is wrapped in () that acts as a function expression. The () acts like calling that function expression.

An example of IIFE

(function() {
  console.log('I am an IIFE')
})();
brk
  • 43,022
  • 4
  • 37
  • 61