Mi sto cazzando con i prototipi per capire meglio come funzionano. Non riesco a capire il motivo per cui non posso chiamare hideHeader, mentre posso accedere a una variabile (this.header.el)Comprensione di JavaScript Prototipi
function App() {
this.init();
this.el = document.getElementById('box');
}
App.prototype.init = function() {
document.write('hello world');
this.header = new Header();
this.header.hideHeader();
this.header.el.style.display = 'none';
};
new App();
function Header() {
this.el = document.getElementById('header');
}
Header.prototype.hideHeader = function() {
this.el.style.display = 'none';
}
osservare ciò che accade quando si sposta la chiamata a 'App()' in basso, e anche notare che 'document.write' sovrascrive il documento – adeneo