Results 1 to 2 of 2

Thread: File API: reader vs. event.target

  1. #1
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default File API: reader vs. event.target

    I have studied many articles and posts to learn about File API and still don't understand why almost all of them use event.target instead of reader. Here are three examples:

    1. File API
    2. https://developer.mozilla.org/en-US/...elected_images
    3. Working with files in JavaScript, Part 2: FileReader | NCZOnline


    The last reference even recommends using event.target:

    The FileReader instance is available inside of the event handler via event.target and it’s recommended to use that instead of referencing the reader variable directly.
    But why is it recommended and widely used? What's wrong with using reader or simpler this instead: DEMO.

    I know this and event.target can be different, but in this case they both refer to the FileReader object.



    While you can use reader.onload, then why not reader.result?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm unfamiliar with this particular script. However there generally are many ways to refer to any given element. And it frequently happens that many elements may be initialized by a single function that reacts to an event on any one of them. At that point the event target is often the more specific way of referring to the element that has had the event occur upon it. However, this way of looking at things is no substitute for understanding which element has been initialized and which element has received the event (sometimes two different elements) and how to obtain - at event time or before, a reference to the desired element or object required to access the properties sought in successfully executing the code. If a particular code's author recommends a particular approach, it's usually best for that code. But other methods may also work, or even be better. We usually can rely upon author recommendations though because they reflect a greater volume of experience with the particular code.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Script For Constantly Updating TXT File Reader
    By M2com in forum JavaScript
    Replies: 1
    Last Post: 10-18-2011, 05:50 AM
  2. Replies: 1
    Last Post: 04-03-2010, 11:21 PM
  3. Replies: 0
    Last Post: 07-03-2009, 07:26 AM
  4. CSV reader ?
    By chrbar in forum Looking for such a script or service
    Replies: 1
    Last Post: 01-21-2008, 10:00 PM
  5. Download File on form submit event
    By mandarsk in forum JavaScript
    Replies: 1
    Last Post: 11-18-2004, 06:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •