How can I access the color
property of the constructor, from the setColor
function?
function Obj() {
this.color = undefined;
}
Obj.prototype.setColor = () => {
for (var k = 0, hex = "0123456789ABCDEF", max = hex.length, random, color = ""; k < 6;
++k, random = Math.floor(Math.random() * max), color += hex[random]);
this.color = "#" + color; // Here i need to change
};
var ball = new Obj();
ball.setColor();
console.log(ball.color);
So, I want to run the setColor
function and change the color
property of Obj
the constructor.
What is the most elegant and simple method, without declare a var to the context and use that?