Liubomyr Mykhalchenko
Liubomyr Mykhalchenko

Reputation: 268

Do I need to use 'new' operator when creating instance of Immutable.Record?

example from docs https://facebook.github.io/immutable-js/docs/#/Record

var ABRecord = Record({a:1, b:2})
var myRecord = new ABRecord({b:3})

can I omit new operator? it seems to work without it as well..

Upvotes: 1

Views: 101

Answers (2)

idleherb
idleherb

Reputation: 1101

At least in the current version, you can omit it. If you look into the source code on GitHub, there is a check that makes sure this is correctly bound if you are omitting new.

Upvotes: 0

Lajos Arpad
Lajos Arpad

Reputation: 76444

It is unsafe to omit it, you might encounter problems in future versions. You can easily test whether a given version of Immutable.js supports this feature, like this:

typeof (Record({})) === "function"

Upvotes: 1

Related Questions