<ul id="list">
<li>list1</li>
<li>list2</li>
<li>list3</li>
</ul>
<hr>
<button id="bt">Изменить цвет!</button>
function Manipulate (idBtn, idUl){
this.btn = document.getElementById(idBtn) ;
this.ul = document.getElementById(idUl);
};
Manipulate.prototype.clicked = function(){
this.btn.onclick = function(){
console.log('Onclick working!'); // working!
this.ul.style.color = 'red'; //TypeError: this.ul is undefined
};
};
const add = new Manipulate('bt', 'list');
add.clicked();
console.log('ul' in add); //true
function(){
console.log('Onclick working!'); // working!
this.ul.style.color = 'red'; //TypeError: this.ul is undefined
};
var that = this;
this.btn.onclick = function(){
console.log('Onclick working!'); // working!
that.ul.style.color = 'red'; //TypeError: this.ul is undefined
};