Skip to main content
added 86 characters in body
Source Link
Majid Fouladpour
  • 30k
  • 21
  • 77
  • 129

You can achieve this with a Proxy.

First define a handler with an apply trap that intercepts calls to the function. Then, using that handler, set the function to be a proxy onto itself. Example:

function add(a, b){
  return a + b;
}

const handler = {
  apply: function(target, thisArg, argumentsList) {
    alertconsole.log('add was called with ' + argumentsList.join(', and '));
    return target(...argumentsList);
  }
};

add = new Proxy(add, handler);

var m = add(3, 5);
console.log('m = ', m);

var n = add(12, 8);
console.log('n = ', n);

You can achieve this with a Proxy.

First define a handler with an apply trap that intercepts calls to the function. Then, using that handler, set the function to be a proxy onto itself. Example:

function add(a, b){
  return a + b;
}

const handler = {
  apply: function(target, thisArg, argumentsList) {
    alert('add was called with ' + argumentsList.join(','));
    return target(...argumentsList);
  }
};

add = new Proxy(add, handler);

add(3, 5);
add(12, 8);

You can achieve this with a Proxy.

First define a handler with an apply trap that intercepts calls to the function. Then, using that handler, set the function to be a proxy onto itself. Example:

function add(a, b){
  return a + b;
}

const handler = {
  apply: function(target, thisArg, argumentsList) {
    console.log('add was called with ' + argumentsList.join(' and '));
    return target(...argumentsList);
  }
};

add = new Proxy(add, handler);

var m = add(3, 5);
console.log('m = ', m);

var n = add(12, 8);
console.log('n = ', n);

Source Link
Majid Fouladpour
  • 30k
  • 21
  • 77
  • 129

You can achieve this with a Proxy.

First define a handler with an apply trap that intercepts calls to the function. Then, using that handler, set the function to be a proxy onto itself. Example:

function add(a, b){
  return a + b;
}

const handler = {
  apply: function(target, thisArg, argumentsList) {
    alert('add was called with ' + argumentsList.join(','));
    return target(...argumentsList);
  }
};

add = new Proxy(add, handler);

add(3, 5);
add(12, 8);