I know how to intercept get`set` and such within a proxy using the following code:
function get( target, prop, receiver ) {
console.log("Intercepted get")
return Reflect.get( target, prop, receiver );
}
var handler = {
'get': get
};
var proxy = new Proxy( new Array(...[7, 1,2,3,4,5]), handler );
I'm unable to replicate this for sort. Adding:
function sort(target, prop) {
console.log("Intercepted sort")
return Reflect.sort(target);
}
var handler = {
'get': get,
'sort': sort
};
Doesn't work. I've also been unable to find documentation. How do I intercept the sort function?
You have to use
getto trap methods.getis called for each property and each method that is read. The name of the property or method is passed intogetas second argumentprop: