Created
July 26, 2018 18:08
-
-
Save domenic/b497fb15167b522758cbf372eaf0f081 to your computer and use it in GitHub Desktop.
ArrayBuffer.prototype.transfer not-really-a-polyfill
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
// This creates a copy, but does detach the source buffer | |
const mc = new MessageChannel(); | |
ArrayBuffer.prototype.transfer = function () { | |
const result = this.slice(); | |
mc.port1.postMessage(this, [this]); | |
return result; | |
}; | |
const ab = new ArrayBuffer(10); | |
console.log(ab.byteLength); | |
const transferred = ab.transfer(); | |
console.log(ab.byteLength); | |
console.log(transferred.byteLength); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment