0

Is there anyway I can add new property to JavaScript seal object

var obj = {"FirstName":"Tom","LastName":"Gorsuch"};
Object.seal(obj);
obj.MiddleName = "Crouis"; // new property is not added
console.log(obj);

Actual Problem

I am working in a frame work, frame has its own implementation of browser API method, but there are some methods that are not implemented yet , unfortunately I need those methods and I am getting error

function not defined

so thought of writing polyfill, Then I came to know they have also seal the object

ozil
  • 6,930
  • 9
  • 33
  • 56

1 Answers1

2

No, that is exactly what Object.seal prevents.

there are some methods that I need to polyfill, but the framework also sealed the object

You can clone the object using Object.assign and extend that, or implement an adapter/facade object that has all the methods you need and calls into the framework.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375