@eewalk11/initialize v1.0.0
InitializeJS
Initialize a new prototype instance by copying properties from an initialization object using the prototype as a guide.
Usage
This simple module can be used to the same effect in 3 different ways:
Initialize()
(constructor) as a functionInitialize(instance, init)
initialize()
as a static functionInitialize.initialize(instance, init)
initialize()
as a methodnew Initialize().initialize(instance, init)
instance
is the prototype instance to initialize.
Property values will be copied from init
.
Initialization failure
Initialization will fail if the arguments are invalid:
instance
must be a non-null object.
Note:undefined
is valid in the constructor.init
can be a falsy value to indicate that the instance should not be modified. If this argument is not falsy, it must be a non-null object.
By default, when initialization fails, initialize()
will alter nothing and return false
. The
global Initialize.strict
flag can be set to true
for an InitializationError
to be thrown if any
static initialization attempt fails. A strict
property on an instance of Initialize
can be set to true
for an InitializationError
to be thrown if an initialization attempt fails from calling the intitialize()
method on that instance.
7 years ago