function Color (r, g, b) {
this.r = r;
this.g = g;
this.b = b;
}
Color.prototype.toString = function () {
return "#"+((((0<<8)+this.r<<8)+this.g<<8)+this.b).toString(16);
};
var red = new Color(255, 0, 0);
console.log(red); //-> #ff0000
var blue = new Color(0, 0, 255);
console.log(blue); //-> #0000ff
var cadetblue = new Color(95, 158, 160);
console.log(cadetblue); //->#5f9ea0
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
21