Import Configuration Items into an Object in AFrameJS

Importing Configuration Items into an Object in AFrameJS just became a lot easier. One of the most repeated tasks when initializing objects (in the init function) is to import configuration items from the "config" parameter. Each class was responsible for importing the config items that it needed, leading to init functions that only had several lines dedicated to importing, then a call to the superclass' import function.

The Old Way

var Class = AFrame.Class( AFrame.AObject, {
    init: function( config ) {
        this.imported = config.imported;
        this.alsoImported = config.alsoImported;

        Class.sc.init.call( this, config );
    },
    ... 
} );

Kind of repetitive and silly, isn't it?

The New Way

var Class = AFrame.Class( AFrame.AObject, {
    importconfig: [ 'imported', 'alsoImported' ],
    ...
} );

This works on classes even if they inherit from another class, the entire class chain will be checked for items to import.

So much cleaner, isn't it?

A demo of this in action can be found at JSFiddle