Skip to content
JS Decorators library
JavaScript Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Simple, vanilla JS type checking through ES7 decorators ...and a few other decorators, to boot.

If you like this project, be sure to check out FluxThis, the immutable Flux framework by AddThis.

npm version Build Status

Type Validation

Throw errors when unexpected types are provided or returned from class or object functions. For more details, see the Type Validator API.

import {param, returns} from 'decorate-this';

class Point {
    constructor() {
        this.x = 0;
        this.y = 0;

    // The first param of this method takes a Point, and will throw
    // a type error if a non-Point is passed
    // The method returns a Number. If it doesn't, a type error will
    // be thrown before the value is returned.
    distanceTo(point) {
        let squaredDistance = (point.x - this.x) ** 2 +
            (point.y - this.y) ** 2;

        return Math.sqrt(squaredDistance);

    // Two number args, no return value
    addToDimensions(x, y) {
        this.x += x;
        this.y += y;


Automatically memoize functions for greater efficiency

import memoize from 'decorate-this';
let obj = {
    // Results of the function are stored in a map, which maps arguments
    // to the function's result. This expensive func is only run a single
    // time for a given a/b pair.
    expensiveFunc(a, b) {
        return Math.sin(Math.sqrt(a ** b));

Property descriptors

import {enumerable, writable, configurable} from 'decorate-this';

class T {
    hiddenMethod() {
        /* ... */


Build up long argument lists with currying

let obj = {
    curriedAdd(a, b, c) {
        return a + b + c;

let addToFive = obj.curriedAdd(5);   // Function
let addToFiveAndThree = addToFive(3);  // Function
let sum = addToFiveAndThree(7);      // 15


Rate-limit expensive or frequently called functions

let obj = {
    @debounce(500) // call after 500ms of no further calls
    debouncedFn(event) {
        console.log(event.clientX, event.clientY);


Similar to returns, but validates the fulfillment value of a promise

let obj = {
    getPoints() {
        return new Promise(resolve => {
            setTimeout(() => resolve([1, 2, 3]), 5000);

Incorporating in your project

npm install decorate-this
  • Build your project with Babel
  • Enable stage 1 (experimental) features
  • Profit
You can’t perform that action at this time.