Skip to content

Instantly share code, notes, and snippets.

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

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);
const transferred = ab.transfer();
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.