Look a magic!!!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Look a magic!!!!

maybe someone could explain ??? https://code.sololearn.com/WXJ0t8X43y70/?ref=app

20th Sep 2018, 4:18 PM
Naty
3 Answers
+ 1
window.onload = onloading(); would make onloading() called the function run immediately during startup, where body element has not been formed yet, so document.body is null. Please note that this is the wrong way to set callback function to onload event. window.onload = onloading; would set the onloading function to be a reference of onload event input, onload event would be fired once all elements are loaded, the event run the callback function onloading and return document.body object. This is the right way to set a callback function to onload event.
20th Sep 2018, 4:29 PM
Calviղ
Calviղ - avatar
+ 2
Calvin thank you for all your help !👍👍👏😊😊😊
20th Sep 2018, 4:40 PM
Naty
+ 1
Naty Please don't worry about my comment (at all), Calvin's correct for your situation. Calviղ Though I can see a use case having the insta-called function return yet another function reference/template(?), I don't have a specific example in mind why this would be a good idea. I'm just mentioning it because after reading your answer I tried it :)
20th Sep 2018, 5:14 PM
Kirk Schafer
Kirk Schafer - avatar