function Proxy

by maxell4o

HTML

<button id="prevent">Click Prevented</button>
<button id="normal">Click Normal</button>

JavaScript

/* function onClick(arg) {
  console.log('onClick:', arg);
}

document.querySelectorAll('button').forEach(v => v.addEventListener('click', (e) => {
  onClick.call(v, e);
}));

onClick = new Proxy(onClick, {
  apply(target, thisArg, argumentsList) {
    if(thisArg.id == 'prevent'){
      console.log('Prevented');
      return;
    }
    console.log(argumentsList);
    target.apply(thisArg, argumentsList);
  }
}) */

let a = new Date();

let formatMe = (target, thisArg, argumentsList) => {
    console.log(this, target, thisArg, argumentsList)
}

function asd(){
		console.log(123, this);
}



a.toJSON = asd.bind()


console.log(1, a.toJSON());