<script>
$(document).ready(function () {
var box = $("-sharpbox1");
function changeColor(color) {
this.color = color;
}
changeColor.prototype.chanCol = function (obj) {
var color = this.color; //
obj.on("click",function () {
$(this).css("background-color",color);
});
}
var ch = new changeColor("red");
ch.chanCol(box);
});
</script>
when I refer to this.color directly in the sentence $(this) .css ("background-color", this.color)
, the color of box does not change, but after assigning the value of this.color to color, I can change it by writing color, box value in css (). Why can"t I write this.color?
just thought about it, is it the relationship of the scope chain?