I understand the recursion point over the deep object to make shallow Object.freezefor each child property. What is the meaning of freezing the value of a function object? The link is already frozen due to shallow freezing at a higher level - is it possible to directly change the value of the function object?
Example:
function deepFreeze (o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if o[prop] != null
&& (typeof o[prop] === "object" || typeof o[prop] === "function") {
deepFreeze(o[prop]);
}
});
return o;
};
var x = {
y: [1,2,3],
z: function(){}
};
deepFreeze(x);
Just trying to understand whether there is something fundamental that I'm here I do not understand, or if it simply protects the mutation function object, for example: x.z.foo = 3.
source
share