Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bmeck
Created May 16, 2014 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmeck/8091494c50d4d820ba5c to your computer and use it in GitHub Desktop.
Save bmeck/8091494c50d4d820ba5c to your computer and use it in GitHub Desktop.
var Buffer = exports.Buffer = exports.SlowBuffer = function(v, encoding)
{
var offset = 0;
if (v instanceof ArrayBuffer)
Uint8ClampedArray.call(this, v, offset)
}
Buffer.prototype = Object.create(Uint8ClampedArray.prototype);
Buffer.prototype.TEST = 'TEST ON OBJECT FROM PROTOTYPE';
var x = (new Buffer(new ArrayBuffer(12)))
x[1] = 123;
x[2] = 456;
console.log('is Buffer: %s, is Uint8Array: %s', x instanceof Buffer, x instanceof Uint8Array);
console.log('x: %s, x.TEST: %s, x[0]: %s, x[1]: %s, x[2]: %s', x, x.TEST, x[0], x[1], x[2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment