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

172
Vistas
How do I intercept sort function within a JS proxy with a function?

My previous related question: How do I intercept sort function within a JS proxy?

Given the proxy:

function sort(customSort) {
  /* Write logs */
  console.log("Intercepted sort")
  return this.sort(customSort);
}
function get( target, prop, receiver ) {
  if (prop === 'sort') {
    /* How to capture custom sort?*/
    return sort.bind(target);
  }
  console.log("Intercepted get")
  return Reflect.get( target, prop, receiver );
}
var handler = {
  get
};
var proxy = new Proxy( new Array(...[7,1,2,3,4,5]), handler );

But now I add a custom sort function:

console.log(proxy.sort((a,b) => .... /* e.g., a-b */))

I cannot understand how to capture the function as to pass it to the proxy sort function. I've tried capturing different arguments in the get function, but can't find the correct one.

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

0

The solution was similar to: How to sort only part of array? between given indexes

I return a function that accesses argument[0]

function sort(customSort) {
  /* Write logs */
  console.log("Intercepted sort")
  return this.sort(customSort);
}
function get( target, prop, receiver ) {
  if (prop === 'sort') {
    /* How to capture custom sort?*/
     return function(customSort) => {
       return this.sort(customSort || ((a,b) => a-b) )
     }
  }
  console.log("Intercepted get")
  return Reflect.get( target, prop, receiver );
}
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