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.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);
}
}
source
share