Not logged in : Login

About: http://ods-qa.openlinksw.com:8896/proxy-iri/296851322ef22bdfcb5f617eac608d67c2f22867     Goto   Sponge   NotDistinct   Permalink

An Entity of Type : schema:DiscussionForumPosting, within Data Space : ods-qa.openlinksw.com:8896 associated with source document(s)

AttributesValues
type
datePublished
  • 2018-07-25T14:26:01Z
  • 2018-07-25T15:22:20Z
publisher
described by
image
  • External Image
mainEntityOfPage
author
position
  • #18
  • #19
dateModified
articleBody
  • impresently: a little confused I know how you feel, I’m not new to JavaScript and I don’t understand it well enough to easily explain it, but it has to do with “closures” and “lexical scope” I think the “Creating closures in loops: A common mistake” section near the end of this page does the best job at explaining that I’ve seen. MDN Web Docs Closures A closure is the combination of a function and the lexical environment within which that function was declared.
  • I’m a little confused on how event objects work. In my for loop the following code works: for (i = 1; i <= 5; i++) { var newImage = document.createElement('img'); newImage.setAttribute('src', "images\/pic" + i + ".jpg"); thumbBar.appendChild(newImage); function displayThumb(clickedImage) { var imageThumb = clickedImage.target.getAttribute('src'); displayedImage.setAttribute('src', imageThumb); }; newImage.addEventListener('click', displayThumb); } While the following does not work: for (i = 1; i <= 5; i++) { var newImage = document.createElement('img'); newImage.setAttribute('src', "images\/pic" + i + ".jpg"); thumbBar.appendChild(newImage); function displayThumb(clickedImage) { var imageThumb = newImage.getAttribute('src'); displayedImage.setAttribute('src', imageThumb); }; newImage.addEventListener('click', displayThumb); } In other words, what is the event object in the displayThumb function doing in the first example that allows it to be functioning on the entire loop, whereas in the second example the loop is completed, and the click events only function on the last thumbnail.
headline
  • "Image gallery" assessment
interactionStatistic
is topic of
is container of of
is object of
is subject of
Faceted Search & Find service v1.17_git38 as of Aug 05 2019


Alternative Linked Data Documents: ODE     Content Formats:       RDF       ODATA       Microdata      About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 08.01.3307 as of May 21 2018, on Linux (x86_64-redhat-linux-gnu-ANALYTICS), Single-Server Edition (7 GB total memory)
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2020 OpenLink Software