色が rgbA、hex、色名、hsl ではなく、rgb 形式であることが確実な場合でも、「rgb(25%,55%,100%)」を使用できます。
function Rgb(rgb){
if(!(this instanceof Rgb)) return new Rgb(rgb);
var c= rgb.match(/\d+(\.\d+)?%?/g);
if(c){
c= c.map(function(itm){
if(itm.indexOf('%')!= -1) itm= parseFloat(itm)*2.55;
return parseInt(itm);
});
}
this.r= c[0];
this.g= c[1];
this.b= c[2];
}
var c= Rgb('rgb(10%,25%,55%)'); alert([cr, cg, cb])
注-キャンバスを使用している場合は、マップがあります。
それ以外は-
Array.prototype.map=Array.prototype.map || function(fun, scope){
var T= this, L= T.length, A= Array(L), i= 0;
if(typeof fun== 'function'){
while(i<L){
if(i in T){
A[i]= fun.call(scope, T[i], i, T);
}
++i;
}
return A;
}
}