Skip to content

Instantly share code, notes, and snippets.

@domenic domenic/transfer.js
Created Jul 26, 2018

Embed
What would you like to do?
ArrayBuffer.prototype.transfer not-really-a-polyfill
// 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
You can’t perform that action at this time.