When you answer this question , I came across the following situation. Note that onclick
in x
is an object with two methods, when the element receives the click executes the click
method which in turn was to execute the funcao_a
method, but returns the following error:
TypeError: x.onclick.funcao_a is not a function at HTMLHeadingElement.click
var x = document.getElementById("title");
x.onclick = {
funcao_a: function() {
console.log('Função A');
},
click: function() {
console.log('Click');
x.onclick.funcao_a();
}
};
x.onclick = x.onclick.click;
<h1 id="title">Somente alguns testes em JS</h1>
But this is not the case when I have an object with a different name, for example: x.objeto
.
var x = document.getElementById("title");
x.objeto = {
funcao_a: function() {
console.log('Função A');
},
click: function() {
console.log('Click');
x.objeto.funcao_a();
}
};
x.onclick = x.objeto.click;
<h1 id="title">Somente alguns testes em JS</h1>
My question is: Is it possible to access this method as in the first example? If yes how?