2011/8/23 Patrick Horgan <[email protected]>:
> I don't understand this either.  How would I add the methods to the
> prototype?

Something like:

ColorObject.prototype = {
  colorNames : {
    aqua : "rgb(0,255,255)",
    black : "rgb(0,0,0)",
    blue : "rgb(0,0,255)",
    fuchsia : "rgb(255,0,255)",
    gray : "rgb(128,128,128)",
    green : "rgb(0,128,0)",
    lime : "rgb(0,255,0)",
    maroon : "rgb(128,0,0)",
    navy : "rgb(0,0,128)",
    olive : "rgb(128,128,0)",
    purple : "rgb(128,0,128)",
    red : "rgb(255,0,0)",
    silver : "rgb(192,192,192)",
    teal : "rgb(0,128,128)",
    white : "rgb(255,255,255)",
    yellow : "rgb(255,255,0)"
  },
  parseColor : function (acolor) {
    var color;
    if (/\d*%/.test(acolor)) {
      color = Math.round(255 * parseInt(acolor.substr(0, acolor.length
- 1)) / 100);
    } else {
      color = parseInt(acolor);
    }
    return color < 0 ? 0 : color > 255 ? 255 : color;
  },
  red : function () {
    return this.colors[0];
  },
  green : function () {
    return this.colors[1];
  },
  blue : function () {
    return this.colors[2];
  },
  tohexStr : function () {
    var output = '#', i = 0; l = this.colors.length;
    for (; i < l; i += 1) {
      output += this.colors[i].toString(16);
    }
    return output;
  },
  torgbStr : function () {
    return "rgba(" + this.colors.join(',') + "," + this.alpha + ")";
  },
  toString : function () {
    return this.torgbStr();
  },
  valueOf : function () {
    var l = this.colors.length, i = l - 1, value = 0;
    for (; i >= 0; i -= 1) {
      value += this.colors[i] << ((l - i - 1) * 8)
    }
    return value;
  },
  mult : function (val) {
    var i = 0, l = colors.length, output = 'rgba(';
    val = val > 1 ? 1 : val < 0 ? 0 : val;
    for (; i < l; i += 1) {
      output += Math.min(Math.round(this.colors[i] * val), 255) + ',';
    }
    return output + this.alpha + ")";
  }
};

For the full code: http://jsfiddle.net/Poetro/mxcxF/

-- 
Poetro

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to