Created
August 15, 2016 16:50
-
-
Save hashedhyphen/bec5cf178d3487f51d0661b2805634f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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