<commit_before># <a name="class"> </a>Class

A fork of [eventEmitter](https://github.com/eventEmitter/ee-class)'s fast prototype based Javascript Class implementation, that is now available in the browser and node.js.

## installation

    npm install storjarn/ee-class

* [Class](#class)
* [EventEmitter](#eventEmitter)
* [Namespace](#namespace)

## API

The Class implementation is built on top of javascript prototype based inheritance and ECMA Script property descriptors.

### Constructor

Classes can be created using the Class function. The function expects exactly one argument, the class definition.

    var MyClass = new Class();

### Class Definition

#### «inherits» property

Objects & Functions on this property are handled as the prototype for the prototype of the class you are creating.

    var MyClass = new Class({
        inherits: Array
    });

    // { // MyClass instance
    //      __proto__: { // MyClass protoype (where your items from the classdefinition are placed)
    //         __proto__: { // the Array prototype
    //              __proto__: {} // the prototype of the array prototype («[Object object]»)
    //          }
    //      }
    // }


#### «function type» properties

Functions will be placed on the Classes prototype object, they are by default not configurable,
not writeable and enumerable (except for properties starting with an «_». If the property has
the name «init» it is treated as the classes constructor.

    var MyClass = new Class({
        init: function(){
            console.log('im executed when the class is instantiated');
        }
    });

    var instance = new MyClass(); // im executed when the class is instantiated

    console.dir(instance); // {} -> the init function is placed on the instances
                           // prototype
    console.log(intance.init); // { [Function: init] super: [Function] }
    console.log(instance instanceof MyClass); // true
    console.log(instance instanceof Object); // true
    console.log(instance instanceof Date); // false


Note the super property on the init function, it can be used to call the constructor of the next
constructor function in the prototype chain.


#### Property Descriptors

The Class definition may contain property descriptor objects. You are able to create
configure each of the properties exactly as you like. You can create getters and setters
and configure the configurability, the writability and the enumerability.


    var Person = new Class({
        init: function(options){
            if (options && options.name !== undefined)  this.name = options.name;
            if (options && options.age !== undefined)   this.age = options.age;
        }

        // the private storage for the age value
        , _storage: {
            value: {
                age: null
            }
        }

        , name: '' // enumerable, writable, not configurable

        , age: {
              get: function(){ return this._storage.age; }
            , set: function(value) {
                if (value < 0) throw new Error('Please provide an age >= 0!');
                else if (value > 150) throw new Error('You are too old, sorry!');<commit_msg>updates readme with abstract class usage<commit_after># <a name="class"> </a>Class

A fork of [eventEmitter](https://github.com/eventEmitter/ee-class)'s fast prototype based Javascript Class implementation, that is now available in the browser and node.js.

## installation

    npm install storjarn/ee-class

* [Class](#class)
* [EventEmitter](#eventEmitter)
* [Namespace](#namespace)

## API

The Class implementation is built on top of javascript prototype based inheritance and ECMA Script property descriptors.

### Constructor

Classes can be created using the Class function. The function expects exactly one argument, the class definition.

    var MyClass = new Class();

### Class Definition

#### «inherits» property

Objects & Functions on this property are handled as the prototype for the prototype of the class you are creating.

    var MyClass = new Class({
        inherits: Array
    });

    // { // MyClass instance
    //      __proto__: { // MyClass protoype (where your items from the classdefinition are placed)
    //         __proto__: { // the Array prototype
    //              __proto__: {} // the prototype of the array prototype («[Object object]»)
    //          }
    //      }
    // }


#### «function type» properties

Functions will be placed on the Classes prototype object, they are by default not configurable,
not writeable and enumerable (except for properties starting with an «_». If the property has
the name «init» it is treated as the classes constructor.

    var MyClass = new Class({
        init: function(){
            console.log('im executed when the class is instantiated');
        }
    });

    var instance = new MyClass(); // im executed when the class is instantiated

    console.dir(instance); // {} -> the init function is placed on the instances
                           // prototype
    console.log(intance.init); // { [Function: init] super: [Function] }
    console.log(instance instanceof MyClass); // true
    console.log(instance instanceof Object); // true
    console.log(instance instanceof Date); // false


Note the super property on the init function, it can be used to call the constructor of the next
constructor function in the prototype chain.

#### «abstract» Classes

Classes can be declared «abstract» by using the class definition property of «isAbstract : true».  This allows the Class to still be inherited but will throw an exception if instantiated directly using the «new» keyword.

    var MyClass = new Class({
        isAbstract: true,
        init: function(){
            console.log('i'll never get executed when the class is instantiated when using the new keyword directly, but will when called from another Class\' constructor by inheritance.');
        }
    });

    var MyChildClass = new Class({
        inherits: MyClass,
        init: function constructor(){
            constructor.super.call(this);
            console.log('i'm executed too');
        }
    });

    var instance = new MyClass(); // ERROR!!!
    var instance2 = new MyChildClass(); // i'll never get executed when the class is instantiated when using the new keyword directly, but will when called from another Class\' constructor by inheritance.  i'm executed too


#### Property Descriptors

The Class definition may contain property descriptor objects. You are able to create
configure each of the properties exactly as you like. You can create getters and setters
and configure the configurability, the writability and the enumerability.


    var Person = new Class({
        init: function(options){
            if (options && options.name !== undefined)  this.name = options.name;
            if (options && options.age !== undefined)   this.age = options.age;
        }

        // the private storage for the age value
        , _storage: {
            value: {
                age: null
            }
        }

        , name: '' // enumerable, writable, not configurable

        , age: {
              get: function(){ return this._storage.age; }
            , set: function(value) {
                if (value < 0) throw new Error('Please provide an age >= 0!');
                else if (value > 150) throw new Error('You are too old, sorry!');
{'fraction_non_alphanumeric': 0.09242566931252523, 'fraction_numerical': 0.0014798869904480022, 'mean_word_length': 2.6441176470588235, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3645964', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1787, 'n_words': 839}