Contracts

A contract could be either a name or a function that mimics a type (e.g Engine, FuelTank declared in the sample above). If a function is given, its name will be used for binding. Thus, following statement:

$.bind(Car).to(Car); // use class Car as contract

is equivalent to:

$.bind('Car').to(Car); // because Car.name === 'Car'

but not equivalent to:

$.bind('my car').to(Car); // because Car.name !== 'my car'

The binding statements for Engine, FuelTank, and Car can be simplified as following:

$.bind(Engine).to(Engine); // equivalent to $.bind('Engine').to(Engine);
$.bind(FuelTank).to(FuelTank); // equivalent to $.bind('FuelTank').to(FuelTank);
$.bind(Car).to(Car).use(Engine, FuelTank); // equivalent to $.bind('Car').to(Car).use('Engine', 'FuelTank');

$(Car).start(); // equivalent to $('Car').start()

Do not use anything that doesn't have any name or use any empty string as contract. Otherwise the container will throw error.

Last updated