I'm coding an unneeded image manipulation library in hopes of learning how to create a simple library or a framework with javascript in a proper and performant way.
Basic flow chart is like the following:
Create Image Object -> Specify URL and Color Mode -> Initiate object so that main manipulation methods are set to specific ones for the color mode of the current image -> Use those manipulation methods.
I am curious about how more experience coders will approach this situation. So if you think there is a better or more fun way to do it please also share your flow charts, I am eager to learn.
Here is my code snippet:
function ImageLib(URL,colormode){
this.url = URL;
this.ColorMode = colormode;
}
ImageLib.prototype.init = function() {
Switch (this.ColorMode ) {
case "BlackAndWhite" :
this.colorEnhance = ImageLib.ColorModeHandlers.BlackAndWhite.method1;
this.resize = ImageLib.ColorModeHandlers.BlackAndWhite.method2;
this.sharpen = ImageLib.ColorModeHandlers.BlackAndWhite.method3;
this.blur = ImageLib.ColorModeHandlers.BlackAndWhite.method4;
break;
case "SemiTransparent" :
this.colorEnhance = ImageLib.ColorModeHandlers.SemiTransparent.method1;
this.resize = ImageLib.ColorModeHandlers.SemiTransparent.method2;
this.sharpen = ImageLib.ColorModeHandlers.SemiTransparent.method3;
this.blur = ImageLib.ColorModeHandlers.SemiTransparent.method4;
break;
case "Sephia" :
this.colorEnhance = ImageLib.ColorModeHandlers.Sephia.method1;
this.resize = ImageLib.ColorModeHandlers.Sephia.method2;
this.sharpen = ImageLib.ColorModeHandlers.Sephia.method3;
this.blur = ImageLib.ColorModeHandlers.Sephia.method4;
break;
case "FullColor" :
case default:
this.colorEnhance = ImageLib.ColorModeHandlers.FullColor.method1;
this.resize = ImageLib.ColorModeHandlers.FullColor.method2;
this.sharpen = ImageLib.ColorModeHandlers.FullColor.method3;
this.blur = ImageLib.ColorModeHandlers.FullColor.method4;
break;
}
};
}
ImageLib.prototype.ColorModeHandlers.BlackAndWhite = {
method1: function (){...},
method2: function (){...},
method3: function (){...},
method4: function (){...}
}
ImageLib.prototype.ColorModeHandlers.SemiTransparent = {
method1: function (){...},
method2: function (){...},
method3: function (){...},
method4: function (){...}
}
ImageLib.prototype.ColorModeHandlers.Sephia = {
method1: function (){...},
method2: function (){...},
method3: function (){...},
method4: function (){...}
}
ImageLib.prototype.ColorModeHandlers.FullColor = {
method1: function (){...},
method2: function (){...},
method3: function (){...},
method4: function (){...}
}
image1 = new ImageLib("url","Sephia");
image1.init();
image1.sharpen();
image1.ColorEnhance();
etc...
First of all, obviously ImageLib.prototype.ColorModeHandlers.Sephia ={...} does't work. I couldn't find any article or question on object.prototype.property.property nesting.
How can I do this? What is the correct way to declare nested properties with sub properties and methods.
And since I couldn't find any article on nested properties like this, is this a bad practice?