Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ee-class

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ee-class

Javascript Class implementation for node.js & ecma script 5 compatible browsers

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ee-class

Javascript Class implementation for node.js

installation

npm install ee-class

build status

Build Status

usage

var Class = require( "ee-class" );


var LifeForm = new Class( {
    isAlive: false

    , init: function( options ){
        this.isAlive = !!options.isAlive;
    }
} );



var Human = new Class( {
    inherits: LifeForm
    
    , name: ""

    // pay attention to give the function a name so you can reference it when you are calling the parent function
    , init: function myInitFunction( options ){
        myInitFunction.parent( options );
        this.name = options.name;
    }
} );



var Boy = new Class( {
    inherits: Human

    , age: 0

    // pay attention to give the function a name so you can reference it when you are calling the parent function
    , init: function myInitFunction( options ){
        myInitFunction.parent( options );
        if ( options.age > 18 ) throw new Error( "Too old to be a boy!" )
        this.age = options.age;
    }


    , describe: function(){
        console.log( "Hi, my name is %s, i'm %s years old and i'm " + ( this.isAlive ? "alive :)" : "dead :(" ), this.name, this.age );
    }
} );



var fabian = new Boy( {
      name:     "fabian"
    , age:      15
    , isAlive:  true
} );

fabian.describe(); // Hi, my name is fabian, i'm 15 years old and i'm alive :)

working with propertiy definers

since version 0.2.7 you may pass an object with object property defintions to the class module.

var MyClass = new Class({
    init: function(){

    }
} 
, { 
    _values: {
        value: {
            name: 'john doe'
        }
    }
    , name: {
        get: function(){
            return this._values.name;
        }
        , set: function(newValue){
            this._values.name = newValue;
        }
        , enumerable: true
    }
});

var x = new MyClass();

x.name = 'michael';
console.log(x.name); // michael

Version History

  • 0.1.0: initial version
  • 0.1.3: fixed integration with eventemitter objects
  • 0.2.0: Added proper implementation for calling super functions, deprecated the «parent» property
  • 0.2.1: Bugfix for the «super implementation»
  • 0.2.2: Deprecated the «super» property and replaced it with the «parent» property beacuse super is a javascript reserved keyword
  • 0.2.3: The constructor takes now n instead of 1 arguments
  • 0.2.4: The constructor may now return a function when overriding the class implementation
  • 0.2.6: Classes expose their defintion now via the «Class.definition» proroperty
  • 0.2.7: Added support fo Object.defineProperties()
  • 0.2.8: Removed all occurences of proto in th eclass implementation, replaced the by Object.getPrototypeOf()

Keywords

FAQs

Package last updated on 06 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc