var Global = {
alpha : 1,
color : 'rgba(0, 0, 0, '+this.alpha+')'
}
console.log(Global.color);
this code is something wrong. In this code, How can i use var alpha in Global.color. Please help me.
var Global = {
alpha : 1,
color : 'rgba(0, 0, 0, '+this.alpha+')'
}
console.log(Global.color);
this code is something wrong. In this code, How can i use var alpha in Global.color. Please help me.
Global.alpha
? Global is a horrible variable name - whose global is it and js is nitpicked for the global scope to begin with.
this.alpha
is looking at the current context (which is not going to be Global) and access It's alpha.
var Global = {
alpha : 1,
getColor : function ()
{
return 'rgba(0, 0, 0, ' + this.alpha + ')';
}
};
console.log(Global.getColor());
I'd do the following:
var Global = { alpha: 1 };
Global.color = 'rgba(0, 0, 0, ' + Global.alpha + ')';
console.log(Global.color);