Hallo, ich probiere gerade etwas herum und habe festgestellt, dass mein Code innerhalb des DOMContentLoaded events aber auch innerhalb von document.readyState nicht lädt. Wenn ich es entferne jedoch schon.
Ich würde nur gerne verstehen, warum. Danke! =)
HTML-Code:
<button onclick = "foo.showBox()">Click ME!!</button>
Code:
document.onreadystatechange = function(){ if( document.readyState === 'complete' ) { console.log( 'document is already ready, just execute code here' ); function Create(id){ this.num = id; } Create.prototype.showBox = function(){ console.log(Object.keys(foo)[0] + " = " + this.num); } var foo = new Create(1234); console.log(Object.keys(foo)); foo.showBox(); } }
Kommentar