JSFiddle - React, Tailwind, and code Playground

JavaScript

function copy(refObject) {
  var newObject = Object.create(Object.getPrototypeOf(refObject));
  var property;

  for (property in refObject) {
    if (refObject.hasOwnProperty(property)) {
      newObject[property] = refObject[property];      
    }
  }

  return newObject;
}
    
var a = {
    type: 'declaration',
    get text() {
     return 'Test message';  
    } 
}
    

var b = copy(a);
console.log(b);