Events in function arguments

I am new to javascript and I am trying to teach myself some of them by looking at the code for online projects that interest me. I was looking at the 3D view code ( source ). This allows you to drag and drop the 3D data files that you want to view. There are a few things in the code palette (shown below) that seem obscure:

  • reader.onload = function (event) ... Not sure what an "event" is here.
  • reader.readAsText (file); ... I do not know why this is done with reader.readAsBinaryString (file); was called earlier.

Thank you, a lot of people :).

    function onFileDrop(evt) {

        evt.stopPropagation();
        evt.preventDefault();

        var file = evt.dataTransfer.files[0]; 

        var splits = file.name.split('.');

        if (splits[splits.length - 1] == 'json') {

            var reader = new FileReader();

            //reader.onerror = errorHandler;
            //reader.onprogress = updateProgress;
            //reader.onabort = 
            //reader.onloadstart = 
            //reader.onload = 

            reader.readAsBinaryString(file);

            reader.onload = function (event) {

                var meshEntityList = JSON.parse(event.target.result);

                createScene(meshEntityList);
            };

            reader.onerror = function (event) {
                alert('Cannot read file!');
            };

            reader.readAsText(file);
        }
    }
+4
source share
1 answer
  • . , "" . , "" . "" .

  • - javascript. Onload onerror - . reader.readAsText(); reader.readAsBinaryString(); , , . , , , onload.

+1

All Articles