Merge pull request #14532 from resilient-tech/setDefault
This commit is contained in:
commit
cfa257929e
1 changed files with 8 additions and 0 deletions
|
|
@ -23,6 +23,14 @@ if (!Array.prototype.uniqBy) {
|
|||
});
|
||||
}
|
||||
|
||||
// Python's dict.setdefault ported for JS objects
|
||||
Object.defineProperty(Object.prototype, "setDefault", {
|
||||
value: function(key, default_value) {
|
||||
if (!(key in this)) this[key] = default_value;
|
||||
return this[key];
|
||||
}
|
||||
});
|
||||
|
||||
// Pluralize
|
||||
String.prototype.plural = function(revert) {
|
||||
const plural = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue