classing 5

Fluent classes for node.js and the browser.


Written in JavaScript by 1 contributor


Need Support?

we offer maintenance, support and development services for all our open source projects.

Contact Us


Build Status

Easy, flexible classes for JavaScript, works in node and all modern browser (> IE8).

Why another class library?

Because none of the other class libs have a good way to associate meta data with properties, and have that meta data easily available in child classes. This is useful for e.g. defining property labels, types, validation rules etc.

Classing presents an API similar to the native Object.defineProperty() and Object.defineProperties() methods.

var Class = require('classing');

var User = Class();

User.defineProperty('name', {
  label: 'Name',
  value: 'anonymous'

  email: {
    label: 'Email Address'
  avatarUrl: {
    label: 'Avatar URL',
    // getter
    get: function () {
      return getGravatarUrl(;


var user = new User({
  name: 'charles',
  email: ''

console.log( + ':',; // "Name: charles"


The main difference between this and the native methods is that the full descriptor declarations are preserved. The native methods discard these extra keys (anything other than enumerable, configurable, writable, value, get and set), making them unsuitable for storing metadata. Classing corrects this and ensures that the descriptors are accessible within child classes.


Via npm:

npm install --save classing

or bower:

bower install --save classing


Simple classes

var Class = require('classing');

var Person = Class({
  name: {
    value: 'No Name'
  dateOfBirth: {}

var person = new Person(); === 'No Name'; // => true

var person = new Person({
  name: 'Bob',
  dateOfBirth: new Date()

Default values

var Collection = Class({
  items: {
    enumerable: false,
    default: function () { return []; }
  length: {
    get: function () {
      return this.items.length;
  push: function () {
    return this.items.push.apply(this.items, arguments);

var list = new Collection();

list.length === 0; // true

list.push(1, 2, 3);

list.length === 3; // true


var Vehicle = Class({
  name: {
    value: 'No Name'

var RoadVehicle = Vehicle.extend({
  wheels: {
    value: 0
  capacity: {
    value: 0
  capacityPerWheel: {
    get: function () {
      return (this.capacity || 1) / (this.wheels || 1)

var Car = RoadVehicle.extend({
  wheels: {
    value: 4

var mini = new Car({
  name: 'mini',
  capacity: 28



var Truck = RoadVehicle.extend();

  capacity: 2,
  wheels: 8

var truck = new Truck();

Auto Binding

var MyConsole = Class.create({
  alert: {
    bind: true,
    value: function (message) {
  log: {
    bind: console,
    value: console.log
  alertCalledCount: {
    value: 0

var myconsole = new MyConsole(),
    alert = myconsole.alert,
    log = myconsole.log;




log('If you can see this in the console, it worked.');

Running the tests

First, npm install, then npm test. Code coverage generated with npm run coverage.


MIT, see

44 other JavaScript projects

fast.jsJavaScript 2930

Faster user-land reimplementations for several common builtin native JavaScript functions.

babel-plugin-typecheckJavaScript 823

Static and runtime type checking for JavaScript in the form of a Babel plugin.

babel-plugin-closure-eliminationJavaScript 223

A Babel plugin which eliminates closures from your JavaScript wherever possible.

orientoJavaScript 212

Former official node.js driver for OrientDB. Fast, lightweight, uses the binary protocol. Now deprecated.

babel-plugin-macrosJavaScript 184

Hygienic, non-syntactic macros for JavaScript via a Babel plugin.

htmlingJavaScript 167

Polymer / HTML5 templating syntax for node.js

babel-plugin-contractsJavaScript 128

Design by Contract for JavaScript via a Babel plugin.

YiiBlocksJavaScript 70

A set of building blocks that provide common functions for Yii web applications

contractualJavaScript 52

Unobtrusive, backwards compatible, syntactic sugar for Design by contract in JavaScript.

gitignore-parserJavaScript 34

A simple .gitignore parser for node.js

modelingJavaScript 14

Fast and flexible data models for node.js and the browser.

binary-protocolJavaScript 13

Easy, fast, writers and readers for implementing custom binary protocols in node.js.

YiiJSJavaScript 11

A port of the Yii PHP framework to JavaScript

url-routeJavaScript 10

Web component providing URL routing

validatingJavaScript 10

Quick and easy validators for node.js and the browser.

babel-plugin-traceJavaScript 6

This is a Babel plugin which adds a straightforward, declarative syntax for adding debug logging to JavaScript applications.

mallocJavaScript 6

Simple malloc() & free() implementation for node.js, built on top of array buffers.

geonames-importerJavaScript 6

Imports geonames data into elasticsearch

castingJavaScript 5

Tiny type casting library for node.js and the browser.

atomicbuffersJavaScript 5

Atomic `readInt32()`, `writeInt32()`, `readUInt32()` and `writeUInt32()` for node.js buffers.

dispatchingJavaScript 5

Tiny routing / dispatch library for node and the browser.

mimingJavaScript 3

Processing and formatting for various mime types.

oriento-query-builderJavaScript 1

A standalone query builder for OrientDB, designed for node.js/io.js and the browser.

bootstrap-tooltipJavaScript 1

Twitter Bootstrap Tooltip plugin packaged for component.js instead of bower

obligationsJavaScript 1

Tiny JavaScript library for preconditions and postconditions, intended for use with Contractual.

bootstrap-transitionJavaScript 1

Twitter Bootstrap Transition plugin packaged for component.js instead of bower


Twitter Bootstrap Popover plugin packaged for component.js instead of bower


A popular romanian card game


Twitter Bootstrap Typeahead plugin packaged for component.js instead of bower


Twitter Bootstrap Tab plugin packaged for component.js instead of bower


Twitter Bootstrap Dropdown plugin packaged for component.js instead of bower


Twitter Bootstrap Carousel plugin packaged for component.js instead of bower


Twitter Bootstrap Collapse plugin packaged for component.js instead of bower


A basic Flex App setup for video broadcasting


Twitter Bootstrap Scrollspy plugin packaged for component.js instead of bower


Twitter Bootstrap Button plugin packaged for component.js instead of bower


Twitter Bootstrap Alert plugin packaged for component.js instead of bower


Twitter Bootstrap Affix plugin packaged for component.js instead of bower


A Sample CRUD application structured by Backbone js and backed by a node restfull api.


JQuery plugin for covering/uncovering DOM elements


Twitter Bootstrap packaged for component.js instead of bower


WebRTC sample code. For testing purposes only.



Twitter Bootstrap Modal plugin packaged for component.js instead of bower