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/937455/object_setDefault.js

  1. // ==UserScript==
  2. // @name object_setDefault
  3. // @namespace bo.gd.an[at]rambler.ru
  4. // @version 0.2
  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.prototype.setDefault = function (key, value) {
  12. if (!(key in this))
  13. this [key] = value;
  14. };