JSFiddle - React, Tailwind, and code Playground

by Anchit Gupta

HTML

<h2>Freezing an object</h2>


<input type="text" id="musicianName" readonly="true" />
<br />

JavaScript

function test() {
}
test.prototype.age = 10;
var obj = new test();

var Musician = {
    FirstName: "Prince",
    MiddleName: "Rogers",
    LastName: "Nelson",
    StageName: "Prince"
};
Object.observe(Musician, function(changes) {
  changes.forEach(function(change) {
      console.log(change);
      console.log("Chnaged from = " + change.oldValue + ", to = " + change.object.StageName);
  });
//Object.observe(Musician,function(){
  //  console.log("changed");
});
Musician.StageName = "The Artist Formerly know as " + Musician.StageName;
Musician.StageName = "Jamie";
Musician.StageName = "Christopher";
setTimeout(function(){ 
    Musician.StageName = "Joey";
}, 1000);
//Musician.StageName = "Prince";
//Musician.prototype = {};
//Musician.prototype.age = 10;


console.info("Before freeze Musician.StageName = " + Musician.StageName);
Object.freeze(Musician);
Musician.StageName = "Chandler";
console.info("After freeze Musician.StageName = " + Musician.StageName);

document.getElementById("musicianName").value = Musician.StageName;

console.log(Musician.hasOwnProperty('FirstName'));
console.log(obj.hasOwnProperty('age'));