new object
by fredericklim
HTML
<p class='x' id='u1'></p>
<p class='x' id='u2'></p>
<button onclick="changeColor()">
Click
</button>
JavaScript
function changeColor() {
let x = document.querySelectorAll('.x');
x.forEach( (i) => i.style.color = 'red' )
}
function User(name) {
//this = {};// (implicitly)
// add properties to this
this.name = name;
this.isAdmin = false;
//return this;// (implicitly)
}
let user1 = new User("fred");
let user2 = new User("april");
document.getElementById('u1').innerHTML = user1.name;
document.getElementById('u2').innerHTML = user2.name;