Writing code to make an app isn't easy. You've got a lot of parts. Some work completely independently, some need other parts to work properly. And some parts may be made from other parts. It gets complicated quicly.
Truck provides several methods to help you create objects, extend objects and write modules with dependencies. The first of these is
$.extend(targetObject, sourceObject). This will add all the properties of sourceObject to targetObject. In doing so, it will replace any properties of the same name on the targetObject with those of sourceObject. With
$.extend we extend the first object with the second object.
If this is not what you want, you can instead use
$.Mixin(sourceObject, targetObject). This will augment the target object with new properties from the source object. This will only add the properties of sourceObject to targetObject if these do not already exist on targetObject. With
$.Mixin we mix the first object into the second object, so the order of arguments is the reverse of
You might have an object that you want to make multiple copies. To do this, you can use
$.Clone. This will create a clone of the object, complete with a prototype chain linking the copy's properties to the original. This is useful where you want to use the prototype chain to reduce the memory footprint of the copies. You would use this in the same situations where you would define a class and use the
new keyword to create new instances.
$.Clone accomplishes the same result without having to define a function constructor and then defining methods directly on the constructor's prototype.
Truck also provides a method to define modules -
$.Modules.add(). This also lets you indicate a module's dependency on other modules. It makes those dependencies available to the module through dependency injection. This allows you to write modules with stubs for when a dependency is not yet implemented.