object_setDefault

If object does not have key, add it.

当前为 2021-06-03 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/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. });