0.0.1 • Published 8 years ago

superify v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

superify

build status

A simple migration friendly library to bring this.super() or this.super.method() on older software.

It could be used once like superify(Object.prototype) to have it available everywhere or it can be used to make it super capable the class at the root of some inheritance.

Example

function A() {
  console.log('A');
}

A.prototype = withSuperContext({
  constructor: A,
  method: function () {
    console.log('method from A');
  },
  get runtime() {
    console.log('runtime A getter');
  }
});

function B() {
  this.super();
  console.log('B');
}

B.prototype = Object.create(A.prototype, {
  constructor: {value: B},
  method: {value: function () {
    this.super.method();
    console.log('method from B');
  }}
});

function C() {
  this.super();
  console.log('C');
}

C.prototype = Object.create(B.prototype, {
  constructor: {value: C},
  runtime: {get: function () {
    this.super.runtime;
    console.log('runtime C getter');
  }}
});


// test
var c = new C();
// A, B, C

c.method();
c.runtime;
0.0.1

8 years ago

0.0.0

8 years ago