Is there a way in javascript to make this work?
// define an user class
var User = function (name) {
this.name = name;
}
// create an user object
var user = new User('John');
var anchor = document.createElement('a');
anchor.innerHTML = user.name;
// add the anchor to DOM
document.body.appendChild(anchor);
// change the user name
user.name = 'James';
After this, the html of the anchor changes the content automatically because its holds a reference to object user. Maybe this sounds dumb, but what I thinking is if is there a way to DOM watch any changes on its values through object reference.
Many thanks.