class Color constructor: (r, g, b, a=255) -> color = CreateColor r, g, b, a color.constructor = c return colorwhite = new Color 255, 255, 255
function Color(r, g, b, a) { var color; if (a == null) { a = 255; } color = CreateColor(r, g, b, a); color.constructor = Color; return color; }
You say "instanceof works" but what does it report for such an object?Other than my small confusion regarding that (I'm probably simply brainfarting and it's probably "[Object Color]" all along), I agree that this is a great and simple method to wrap Sphere's native object creators
var color = new Color(255, 255, 255); // actually returns a Sphere color objectcolor instanceof Color // true
function Color(r, g, b, a) { var color; if (a == null) { a = 255; } color = CreateColor(r, g, b, a); color.constructor = Color; color.__proto__ = Color.prototype; return color; } Color.prototype.grayscale = function() { return (this.red + this.green + this.blue) / 3; }