Skip to content

Instantly share code, notes, and snippets.

@hashedhyphen
Created August 15, 2016 16:50
Show Gist options
  • Save hashedhyphen/bec5cf178d3487f51d0661b2805634f5 to your computer and use it in GitHub Desktop.
Save hashedhyphen/bec5cf178d3487f51d0661b2805634f5 to your computer and use it in GitHub Desktop.
class CustomBuffer {
constructor(...args) {
const symBuf = Symbol("Buffer");
this[symBuf] = Buffer.alloc(...args);
return new Proxy(this, {
get(target, prop) {
return (prop in target)
? target[prop]
: target[symBuf][prop]; // delegate
}
});
}
hello() {
console.log("hello");
}
}
const buf = new CustomBuffer(16);
buf.hello();
for (let val of buf) {
console.log(val);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment