出于好奇,是否有办法从paint
函数访问this.color
?
function Foo(color)
{
this.color = color;
this.paint = function paint()
{
$("select").each(function(idx, el)
{
$(el).css("background", color); // OK
// $(el).css("background", this.color); // this.color is undefined
})
}
}
new Foo("red").paint();
谢谢
var that = this;
function (idx, el) {
// access what used to be this.color as that.color
}