Skip to content
Advertisement

Set default value of Javascript object attributes

Is there a way to set the default attribute of a Javascript object such that:

JavaScript

Advertisement

Answer

Since I asked the question several years ago things have progressed nicely.

Proxies are part of ES6. The following example works in Chrome, Firefox, Safari and Edge:

JavaScript

Read more in Mozilla’s documentation on Proxies.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement