object_setDefault

If object does not have key, add it.

As of 2021-06-03. See the latest version.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/427473/937458/object_setDefault.js

  1. // ==UserScript==
  2. // @name object_setDefault
  3. // @namespace bo.gd.an[at]rambler.ru
  4. // @version 0.3
  5. // @description If object does not have key, add it.
  6. // @author Bogudan
  7. // @license LGPLv3
  8. // @include https://localhost/
  9. // ==/UserScript==
  10.  
  11. Object.defineProperty (Object.prototype, 'setDefault', {
  12. value : function (key, value) {
  13. if (!(key in this))
  14. this [key] = value;
  15. }
  16. });