Travis build: 342 [cron]
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -995,6 +995,26 @@
|
|||||||
"hash": "31714831376eeddd863a295af778632f584468745fbeb4e9a6f62b5275ea3562"
|
"hash": "31714831376eeddd863a295af778632f584468745fbeb4e9a6f62b5275ea3562"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "deepFreeze",
|
||||||
|
"type": "snippet",
|
||||||
|
"attributes": {
|
||||||
|
"fileName": "deepFreeze.md",
|
||||||
|
"text": "Deep freezes an object.\n\nCalls `Object.freeze(obj)` recursively on all unfrozen properties of passed object that are `instanceof` object.",
|
||||||
|
"codeBlocks": [
|
||||||
|
"const deepFreeze = obj =>\n Object.keys(obj).forEach(\n prop =>\n !obj[prop] instanceof Object || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop])\n ) || Object.freeze(obj);",
|
||||||
|
"'use strict';\n\nconst o = deepFreeze([1, [2, 3]]);\n\no[0] = 3; // not allowed\no[1][0] = 4; // not allowed as well"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"object",
|
||||||
|
"recursion"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"archived": false,
|
||||||
|
"hash": "24b3dd66c4b69577d70917ba4f0c119a7ad21497d18704b7150c3693673b5e53"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "defaults",
|
"id": "defaults",
|
||||||
"type": "snippet",
|
"type": "snippet",
|
||||||
|
|||||||
@ -1,17 +1,6 @@
|
|||||||
const deepFreeze = obj => {
|
const deepFreeze = obj =>
|
||||||
Object.freeze(obj);
|
Object.keys(obj).forEach(
|
||||||
|
prop =>
|
||||||
Object.getOwnPropertyNames(obj).forEach(function(prop) {
|
!obj[prop] instanceof Object || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop])
|
||||||
if (
|
) || Object.freeze(obj);
|
||||||
obj.hasOwnProperty(prop) &&
|
|
||||||
obj[prop] !== null &&
|
|
||||||
(typeof obj[prop] === 'object' || typeof obj[prop] === 'function') &&
|
|
||||||
!Object.isFrozen(obj[prop])
|
|
||||||
) {
|
|
||||||
deepFreeze(obj[prop]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
module.exports = deepFreeze;
|
module.exports = deepFreeze;
|
||||||
|
|||||||
3238
test/testlog
3238
test/testlog
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user