I want to create a custom image constructor:
var image1 = new imgConstructor("picture.png", 100, 50);
I have tried:
var imgConstructor = function(src, width, height) {
this = new Image(width, height);
this.src = src;
}
but this = new Image()
is invalid.
I know I can do it with factory function like:
var imgConstructor = function(src, width, height) {
var img = new Image(width, height);
img.src = src;
return img;
}
var image1 = imgConstructor("picture.png", 100, 50);
But I want to do with constructor, using "new". Any ideas?