Greasy Fork is available in English.

object_setDefault

If object does not have key, add it.

2021/06/03のページです。最新版はこちら。

このスクリプトは単体で利用できません。右のようなメタデータを含むスクリプトから、ライブラリとして読み込まれます: // @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;
	    }
    });