<html>
<head>
</head>
<body>
<div>123123</div>
<div>123123</div>
</body>
<script>
function Cl (obj, color1, color2) {
this.color1 = color1;
this.color2 = color2;
this.obj = obj;
obj.style.backgroundColor = color1;
this.obj.onclick = Cl.prototype.method.bind(this.obj, this);
}
Cl.prototype.method = function (obj, e) {
console.log(obj);
console.log(e);
console.log(this);
this.style.backgroundColor = this.style.backgroundColor == obj.color2 ? obj.color1 : obj.color2;
}
var divs = document.querySelectorAll('div'),
div1 = divs[0],
div2 = divs[1];
var obj1 = new Cl(div1, 'red', 'yellow');
var obj2 = new Cl(div2, 'white', 'green');
</script>
</html>