Welcome to WebmasterWorld Guest from 54.196.224.166

Forum Moderators: open

Message Too Old, No Replies

File API: reader vs. event.target

     

Rain_Lover

6:01 pm on May 20, 2014 (gmt 0)

5+ Year Member Top Contributors Of The Month



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 [w3.org]
  2. Using files from web applications | MDN [developer.mozilla.org]
  3. Working with files in JavaScript, Part 2: FileReader | NCZOnline [nczonline.net]


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 [jsfiddle.net].

I know
this
and
event.target
can be different, but in this case they both refer to the
FileReader
object and
result
is in fact a FileReader property [developer.mozilla.org] -- just like
onload
, which is a FileReader event [developer.mozilla.org].
 

Featured Threads

Hot Threads This Week

Hot Threads This Month