After sealing the object with Object.seal() in es5, can the properties on the object prototype be modified?
漂亮男人
漂亮男人 2017-06-10 09:49:20
0
2
964

mdn’s explanation is this

The translation said that the inherited attributes on the prototype will not be affected, but the value of the __proto__ attribute cannot be modified. Then I tested it myself and found that the prototype can be deleted and modified after sealing the object, and then I did not understand this sentence. whether the expression is accurate. . .
code show as below

let obj_origin, obj_changed;

        function Person() {
            this.name = 'sheng';
            this.age = '25';
        }

        Person.prototype = {
            constructor: Person,
            sing () {
                alert('sing');
            },
            prototypeTarget:'prototypeTarget'
        };

        obj_origin = new Person();

        obj_changed = Object.seal(obj_origin);

        delete obj_changed.name;

        delete obj_changed.__proto__.prototypeTarget;

        console.log(obj_changed);


The prototypeTarget attribute on the prototype has been deleted

漂亮男人
漂亮男人

reply all(2)
刘奇

Normally, an object is extensible (new properties can be added). Sealing an object makes it impossible to add new properties, and all existing properties become non-configurable. The effect of a property being non-configurable is that the property becomes non-deletable, and a data property cannot be redefined as an accessor property, or vice versa. But the property's value can still be modified. Attempting to delete a property of a sealed object or convert a property of a sealed object from a data property to an accessor property will fail silently or throw a TypeError exception (strict mode).

Does not affect properties inherited from the prototype chain. But the value of the proto attribute cannot be modified.

Information comes from: https://developer.mozilla.org...

巴扎黑

_proto_ is an internal private property, not a prototype property

For details, please read https://developer.mozilla.org...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template