delly

0.0.0 • Public • Published

Delly

Simple method delegation helper. Method delegation is an alternative to inheritance.

Install

npm install delly

Example

var delegate = require('delly')

function Dialog(){}

Dialog.prototype = {
  show: function(){
    console.log('Showing dialog')
  },
  close: function(){
    console.log('Closing dialog')
  }
}

// A lot of people would have FancyDialog
// inherit from Dialog here, but instead we'll
// use delegation
function FancyDialog(){
  this.dialog = new Dialog
}

FancyDialog.prototype = {
  addBackdrop: function(){
    console.log('Adding backdrop')
  },
  // here we'll explicitly delegate each method
  // we want to delegate to `this.dialog`
  show: delegate('dialog', 'show'),
  close: delegate('dialog', 'close')
}

Readme

Keywords

none

Package Sidebar

Install

npm i delly

Weekly Downloads

1

Version

0.0.0

License

MIT

Last publish

Collaborators

  • airportyh