Skip to content

Super easy delegating method and accessor, using es6 Proxies with less than 15 lines of code

License

Notifications You must be signed in to change notification settings

fundon/delegate-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

delegate-proxy

Super easy delegating method and accessor, using es6 Proxies with less than 15 lines of code.

Installation

$ npm install delegate-proxy

Examples

const delegateProxy = require('delegate-proxy')

const bar = {
  n: 1,

  add (i) {
    this.n += i
  }
}

const foo = {

  set (n) {
    this.n = n | 0
  },

  sub (i) {
    this.n -= i
  }

}

const d = delegateProxy(foo, bar)

bar       // { n: 1, end: [Function: end] }
foo       // { set: [Function: set], sub: [Function: sub] }
d         // {}

d.n       // => 1
d.add(1)
d.n       // => 2

d.sub(2)
d.n       // => 0

d.set(1)
d.n       // 1

d.n = 233
d.n       // 233

Badges

Build Status codecov


fundon.me  ·  GitHub @fundon  ·  Twitter @_fundon

About

Super easy delegating method and accessor, using es6 Proxies with less than 15 lines of code

Resources

License

Stars

Watchers

Forks

Packages

No packages published