The reason why you have to use 'results.push(res)' instead of 'this.results.push(res)' is that the context of 'this' has changed and it doesn't point to the global context any more (under which results array is defined).
Instead this points to the image element that triggered error event.
Also please note that 'this' context of the 'fun1' will depend on the calling object. If it is called in global scope then 'this.results' will be defined, otherwise it will be undefined (in scope of the fun1). In addition, this also depends on the fact if function is defined in 'strict' or 'non-strict' mode.
Let say that you have three different image elements and the same error event handler in all functions 'this' will be different in all of them. Actually in every function 'this' will correspond to the DOM element that triggered error event (image1, image2 or image3), as Felix Kling already wrote under comments.
Also, I would like to point out that you could actually have a valid error event handler function in which 'this.results' would work. To accomplish this you will have to call your error event handler function using 'call', 'apply' or 'bind' methods which allow you to change context of this inside of the function.
You could say:
// define your onError event handler
var onError = function () {
var endtimer = new Date().getTime();
res = (endtimer - starttimer);
this.results.push(res);
$('#results').html("" + res + "ms");
};
// now call it this way
$(imag).attr('src', str1 + ':8886/').error(onError.bind(this));
Of course, this way using 'this' you could not access your image properties as context of this has changed (in your example you are not using image properties, so no harm here).
To better understand javascript global and function context read more on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this.
Hope this helps.