Home

Awesome

<i>Update 09.03.15: "polymorphic mode" and "full export" features are deprecated.</i>

#Standalone version of Lava.ClassManager

npm npm

One of the fastest and most convenient class systems in the world.

Quick facts:

Docs:

Standalone version is self-contained (it does not have any dependencies, like the main framework).

##Performance

Performance comparison of the fastest class systems:

For your convenience, performance tests have their own repository: https://github.com/kogarashisan/PerfTests

##Performance notes

ClassManager can generate classes in two modes, depending on is_monomorphic switch. Monomorphic mode generates classes with slower constructors, but fast method calls (due to the fact, that all class instances will have the same internal type, reducing method polymorphism). Polymorphic mode generates fast constructors with slower method calls.

<b>Constructor generation performance</b>

Creating a class constructor takes some time in all class systems (not class instance, but the constructor). There are no performance tests for class definitions, cause it's not fair to compare browser-only class systems with language preprocessors.

You should know, that class generation in ClassManager is slower in comparison to other systems, but:

##Usage example

ClassManager is available as NPM module, which can be installed with the following command:

npm install lava-class-manager

You may either require("lava-class-manager") (in Node.js environment) or include it directly in browser. You will get a <i>partial copy of Lava object</i> with ClassManager and it's dependencies.

// in Node.js environment:
var Lava = require("lava-class-manager");
// in browser:
// <script src="path/to/ClassManager/lib/class_manager.js"></script>

// namespaces is a must
Lava.ClassManager.registerRootNamespace('global', window);

Lava.ClassManager.define(
'global.Animal',
{
	name: null,
	steps: 0,
	food: [], // will NOT be shared across class instances
	
	// constructor
	init: function(name) {
		this.name = name;
	},
	walk: function() {
		this.steps++;
	}
});

Lava.ClassManager.define(
'global.Cat',
{
	Extends: 'global.Animal',
	init: function(name) {
		this.Animal$init(name); // parent method call
	}
});

var cat = new Cat("Garfield");
cat.walk();

Lava.instanceOf(cat, "global.Animal");

##JSDoc annotations and IDE support

You can help IDE to recognize ClassManager inheritance model by adding proper JSDoc comments to each class:

Lava.define(
'Lava.data.MetaStorage',
/**
 * @lends Lava.data.MetaStorage#
 * @extends Lava.data.ModuleAbstract
 * @extends Lava.mixin.Properties
 */
{
	Extends: 'Lava.data.ModuleAbstract',
	Implements: 'Lava.mixin.Properties',
	// ...
});

Parent class and all mixins should be listed with @extends JSDoc tag - this will enable IDE hinting for parent members. Class itself should be exported by @lends tag - this will enable hinting on constructed object instances. This technique works in PHPStorm. Unfortunately, parent method calls can not be automatically recognized at this moment.

##Extras

You can reuse several classes, that come with the main framework:

##Limitations

While using compression - you can not mangle method names in class bodies, cause this will break inheritance. Good-behaving compression tools will not do it, anyway.

There is no official way to define a true private method: private methods in JavaScript are considered bad practice by the author, cause they usually come at cost of inflexibility and speed. Instead, you are recommended to use protected methods (name begins wih underscore). But if you really need it - you can create a private method with traditional techniques.

##Changelog

<b>1.1.0</b>

Light performance improvements.

<b>1.0.3</b>

<b>1.0.2</b>

<b>1.0.1</b>