- Source:
This is a flag trait that indicates whether a type is immutable.
const {Immutable, isImmutable, typeIsImmutable} = require('ferrum');
// Mark a custom type as immutable
class Foo {
[Immutable.sym]() {}
};
// Or alternatively
Immutable.impl(Foo, true);
// Mark a custom value as immutable
const bar = {};
Immutable.implStatic(bar, true);
// Test a type for immutability
typeIsImmutable(Foo); // => true
typeIsImmutable(Number); // => true
typeIsImmutable(Object); // => false
// Test a value for immutability
isImmutable(42); // => true
isImmutable({}); // => false
isImmutable(bar); // => true
// Any other classes will not be considered immutable by default
class Bang {};
typeIsImmutable(Bang); // => false
Since javascript has not real way to enforce absolute immutability this trait considers anything immutable that is hard to mutate or really not supposed to be mutated. Function is considered immutable despite it being possible to assign parameters to functions...
This is used in a couple paces; specifically it is used as a list of types
that should be left alone in deepclone and shallowclone.
See: isImmutable See: typeIsImmutable
By default implemented for: String, Number, Boolean, RegExp, Date, Symbol, Function, null, undefined