Javascript Proxy gives Illegal invocation error

by Qian Chen   Last Updated August 13, 2019 22:26 PM

I cannot figured out why I got Uncaught TypeError: Illegal invocation error when calling getAttribute from a Javascript proxy.

https://jsbin.com/raqafazixe/1/edit?html,js,console

Here's the HTML code:

<div id="a"></div>

Here's the Javascript code:

const a = document.querySelector('#a');
console.log(a.getAttribute('id'));
console.log(new Proxy(a, {}).getAttribute('id'));

And here's the output:

a
Uncaught TypeError: Illegal invocation
Tags : javascript


Related Questions


Updated March 15, 2017 04:26 AM

Updated May 20, 2017 20:26 PM

Updated February 05, 2018 07:26 AM

Updated July 28, 2019 07:26 AM

Updated October 25, 2017 02:26 AM