Steve Van Opstal
Steve Van Opstal

Reputation: 1121

HTML5 Canvas: Create a Image.onload() function via Image.prototype

So, my goal is to have a simple function that allows me to just type something like:

var map = new Image();
map.onloadDraw();
map.src = "images/" + worldmapCanvasShapeImage;

which will automatically refresh the canvas when loaded.

This is what I already came up with:

Image.prototype.onloadDraw = function(){
    this.onload() = function() {
        drawMap();
        drawMarkers();
        drawArticles();
    }
}

It doesn't seem to work, it's probably a small error but I can't find a lot of information about it.

Upvotes: 3

Views: 725

Answers (1)

alex
alex

Reputation: 490443

Image.prototype.onloadDraw = function(){
    this.onload = function() {
        drawMap();
        drawMarkers();
        drawArticles();
    }
}

Skip the pair of parens after onload. You are defining it, not invoking it. :)

Upvotes: 1

Related Questions