@prefix sioc: . @prefix ns1: . ns1:pagehtml5md sioc:container_of . @prefix rdf: . rdf:object . @prefix foaf: . foaf:topic . sioc:container_of . @prefix schema: . rdf:type schema:DiscussionForumPosting ; schema:datePublished "2018-07-25T14:26:01Z" , "2018-07-25T15:22:20Z" . @prefix ns5: . schema:publisher ns5:a439a40f76abb0743be66578b73891a13f811734 . @prefix pwdr: . pwdr:describedby , ; schema:image ; schema:mainEntityOfPage ; schema:author , ns5:dde0d3087d940b36af9c6f41b057eda0d009700f ; schema:position "#19" , "#18" ; schema:dateModified <2018-07-25T14:29:54Z> , <2018-07-25T15:23:02Z> ; schema:articleBody "\n\n\n\n impresently:\n\na little confused\n\n\nI know how you feel, I\u2019m not new to JavaScript and I don\u2019t\nunderstand it well enough to easily explain it, but it has to do\nwith \u201Cclosures\u201D and \u201Clexical scope\u201D\nI think the \u201CCreating closures in loops: A common mistake\u201D\nsection near the end of this page does the best job at explaining\nthat I\u2019ve seen.\n\n MDN Web Docs\n\nClosures\nA closure is the combination of a function and\u00A0the lexical\nenvironment within which that function was declared.\n\n\n\n\n" , "\nI\u2019m a little confused on how event objects work.\nIn my for loop the following code works:\nfor (i = 1; i <= 5; i++) {\n var newImage = document.createElement('img');\n newImage.setAttribute('src', \"images\\/pic\" + i + \".jpg\");\n thumbBar.appendChild(newImage);\n function displayThumb(clickedImage) {\n var imageThumb = clickedImage.target.getAttribute('src');\n displayedImage.setAttribute('src', imageThumb);\n };\n newImage.addEventListener('click', displayThumb);\n}\n\nWhile the following does not work:\nfor (i = 1; i <= 5; i++) {\n var newImage = document.createElement('img');\n newImage.setAttribute('src', \"images\\/pic\" + i + \".jpg\");\n thumbBar.appendChild(newImage);\n function displayThumb(clickedImage) {\n var imageThumb = newImage.getAttribute('src');\n displayedImage.setAttribute('src', imageThumb);\n };\n newImage.addEventListener('click', displayThumb);\n}\n\nIn other words, what is the event object in the displayThumb\nfunction doing in the first example that allows it to be\nfunctioning on the entire loop, whereas in the second example the\nloop is completed, and the click events only function on the last\nthumbnail.\n" ; schema:headline "\"Image gallery\" assessment" . @prefix ns7: . ns7:interactionStatistic , . ns5:a4e3414407642c3d39af548eb8eb3a97ce2f3c03 rdf:object . ns5:b808712d6dc0cae1aa79b38a930e1f90e3580307 rdf:subject . rdf:subject . rdf:subject . ns5:c92047361d3ee4e3173b7418cb58bf5a65bb054a rdf:subject . rdf:subject . rdf:subject . rdf:subject . ns5:a3ba011a4108aa6e82adfa8870dbefa3d32304db rdf:subject . rdf:subject . ns5:d681ba5dae91d7414b1d7afff2672132186072d1 rdf:subject . rdf:subject . ns5:e241e68a733bd5f122e0dbd537f712f5dc7110e2 rdf:subject . rdf:subject . rdf:subject . rdf:subject . ns5:f775146144c78de64d32b641dab04942ce84e9a1 rdf:subject . rdf:subject .