As the
onload is called asynchronously, you need to use a callback function:
- preload: function(source, callback) {
- var proto = new Image();
- proto.onload = function() {
- var w = proto.width;
- var h = proto.height;
- delete proto;
- callback({width: w, height: h});
- };
- proto.src = source;
- }