Values

$.value(a value object);

This returns a Value Object instead of a must-build dependency. For e.g car color, car model are properties which can accept values other than some must-build objects.

Let's say you want to add_model_to your Car. The model could be a string:

function Car(engine, fuelTank, manufacturer, model) {

    this.toString = function() {
        return `Manufacturer: ${manufacturer.name} | Model: ${model}`;
    }
};

Now let's build your car using a fixed model:

$.bind('my car').to(Car).use('an engine', 'a fuel tank', 'BMW', $.value('320i'));

console.log($('my car').toString()) // "Manufacturer: BMW | Model: 320i"

The value given in$.value()could be anything and will be returned intact.

Last updated