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://updategreasyfork.deno.dev/scripts/427473/937458/object_setDefault.js

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

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