object_setDefault

If object does not have key, add it.

As of 03.06.2021. See ბოლო ვერსია.

ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @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;
	    }
    });