1.0.0 • Published 7 years ago

@eewalk11/initialize v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

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:

  1. Initialize() (constructor) as a function
    Initialize(instance, init)

  2. initialize() as a static function
    Initialize.initialize(instance, init)

  3. initialize() as a method
    new 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.