JavaScript: "TypeError: Illegal invocation" but I did not call any function

0

Note: I asked the same question on stackoverflow.com , but without much success. I researched this error, but all I found was about invoking functions. I'm not invoking any function, I'm just trying to access a property. Some say it's a matter of getters, but it might not be that easy.

So this error pops up when I run this code:

var a = document.getElementById("something");
var b = Object.create(a);
console.log(b.baseURI) //Dá erro com qualquer propriedade de b
<p id="something">Olá! Eu exito apenas para propósitos de demonstração. Este erro ocorre com todos os elementos HTML.</p>

I have no idea why it should happen. It works fine if I use the prototype of b ...

var a = document.getElementById("something");
var b = Object.create(a);
console.log( Object.getPrototypeOf(b.baseURI) ) //Funciona

... just like using a "normal" object for a .

var a = {foo: "Foo!"};
var b = Object.create(a);
console.log(b.foo) //Funciona

Why does this happen? I do not think it makes any sense. The browser is supposed to go through the prototype chain below until it finds a property with the same name. At first I thought that was the problem, but it is not.

As you can see in this image , the properties of a appear in b , not only in b.__proto__ , even more as if they had getters. None of this happens to "normal" objects ( Image ).

If anyone has any idea why this happens, please respond. Thank you.

    
asked by anonymous 13.04.2018 / 20:29

0 answers