Class Plugins Added to AFrameJS

Class Plugins have been added to AFrameJS! What this means is that you can create a class where every created instance of the class has a particular plugin attached. This is very useful for in instances where the code within your class depends on a particular plugin being present. A good example of this is creating a Collection Class that has a CollectionPluginModel attached to it. The user of your collection class should not need to instantiate the collection you created, but have to remember to attach a CollectionPluginModel to it. This example is the modified form of a snippet taken from a project I am currently working on.

Example of Defining a Class with a Class Plugin

The full example can be found on JSFiddle.

var userSchemaConfig = {
    id: 'string',
    name: 'string',
    employer: 'string',
    location: 'string'
};

// Define the Users class which has a class plugin
// of AFrame.CollectionPluginModel
var Users = AFrame.Class( AFrame.CollectionArray, {
	plugins: [ [ AFrame.CollectionPluginModel, {
		schema: userSchemaConfig
	} ] ]
} );

// Create an use a users instance.
var users = Users.create();

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Google Buzz Post to Reddit Post to Slashdot Post to StumbleUpon Post to Technorati

Comments are closed.