Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
where is Buffer.forEach specified?

I know that I can iterate over a Buffer with:

for( const b of buffer ){
  console.log(b);
}

But I noticed I can also call .forEach, .map, etc.

$ node
> const buffer = new Buffer.from([1,2,3]);
undefined
> buffer.forEach( b => console.log( b ) );
1
2
3
undefined
> buffer.map( b => 'value:' + b.toString() ).toString();
'\x00\x00\x00'

Apparently these methods are not specified on the node.js Buffer page, and also I don't understand why it behaves as it does (e.g. '\x00\x00\x00').

Where are the methods .forEach, .map, etc. on the Buffer type specified ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Right from the Nodejs Buffer doc.

Buffer instances are also JavaScript Uint8Array and TypedArray instances. All TypedArray methods are available on Buffers.

And, you can see all sorts of methods on a TypedArray including the ones you mention in your question.

If you go look at the implementation of the nodejs Buffer object, you will see that it is made from something they refer to as a FastBuffer. That inherits a bunch of things from Uint8Array which is likely where the methods you asked about come from:

class FastBuffer extends Uint8Array 

And, there is also a function used to populate the prototype with all sorts of additional methods here.


And, for a little diagnostics, if you run this code in nodejs:

let b = Buffer.alloc(100);

console.log(`Buffer instanceof Buffer: ${b instanceof Buffer}`);
console.log(`Buffer instanceof Uint8Array: ${b instanceof Uint8Array}`);

you will see this output:

Buffer instanceof Buffer: true
Buffer instanceof Uint8Array: true

And, then if you walk the prototype chain with this:

let proto = Buffer.prototype;
while (proto) {
    console.log(proto.constructor.name);
    proto = Object.getPrototypeOf(proto);
}

You will get this output that shows the class inheritance:

Buffer
Uint8Array
TypedArray
Object
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda