object_setDefault

If object does not have key, add it.

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.org/scripts/427473/937466/object_setDefault.js

// ==UserScript==
// @name         object_setDefault
// @namespace    bo.gd.an[at]rambler.ru
// @version      0.5
// @description  If object does not have key, add it.
// @author       Bogudan
// @license      LGPLv3
// ==/UserScript==

(function () {
    function setDefault (key, value) {
        if (!(key in this))
            this [key] = value;
        }
    Object.defineProperty (Object.prototype, 'setDefault', {
        get : () => setDefault,
        set : () => {},
        });
    }) ();