JSFiddle - React, Tailwind, and code Playground

by Samar Pattanayak

JavaScript

var a = {
  id: 2,
  name: 'Samar',
  add: function() {}
};
//var b={id:2,name :'Samar',add1 : function(){}};
console.log(JSON.stringify(a))//only Properties will be displayed not methods like "add"

//console.log(JSON.stringify(a)==JSON.stringify(b));
//var b=a;
//b.id=23;
var b = Object.create(a, {
  add: {
    value: 'nnnn'
  }
});
console.log("B", JSON.stringify(b))//cant stringify instance's 
console.log("A", JSON.stringify(a))
console.log(b);
//Assign//
console.log("Assign Demo")
var c = JSON.parse(JSON.stringify(a));
c.id = "67"
  //var objectIsNew = JSON.parse(JSON.stringify(objectIsOld));
console.log(c)//Here we changed id value and its not getting changed at a
console.log(a)

//Stringify
function replacer(key, value) {
  // Filtering out properties
  if (typeof value === 'string') {
    return undefined;
  }
  return value;
}

var foo = {
  foundation: 'Mozilla',
  model: 'box',
  week: 45,
  transport: 'car',
  month: 7
};
JSON.stringify(foo, replacer);
//As an array
JSON.stringify(foo, ['week', 'month']); //it willkeep only week and month in foo object and stringify
console.log("EOM****************");

var af = function() {
  this.id = 90
}
af.prototype.aff = function() {
  console.log("Prototype FUnction 1")
}
af.prototype.aff2 = function() {
  console.log("Prototype FUnction 2")
}
var afo = new af();
var bf = function() {
    af.call(this); // it only inherits in body methods n properties
}
//bf.prototype = new af(); can replace line 1,2,3 with this line.

bf.prototype = Object.create(af.prototype); //2
bf.prototype.constructor = bf; //3 line 2 and 3 inherits propertis and mtehods added through Prototype

var bfo = new bf();

console.log("afo", afo);
console.log("bfo", bfo);
bfo.aff();
bfo.aff2()
//
var d={id:2};
var e=Object.create(d);
console.log(d,e)
e.id=90;
console.log(e.id);
delete e.id;
delete d.id;
console.log(d.id);
console.log(e.id);