Skip to content

defineReactive doesn't handle inherited properties #3610

@Bernardo-Castilho

Description

@Bernardo-Castilho

The defineReactive function uses getOwnPropertyDescriptor, which works only for properties declared on the object itself, but not on its ancestors:

/**

  • Define a reactive property on an Object.
    */
    function defineReactive (obj, key, val, customSetter) {
    var dep = new Dep()

    var property = Object.getOwnPropertyDescriptor(obj, key)
    if (property && property.configurable === false) {
    return
    }

IMHO, this should be:

/**

  • Define a reactive property on an Object.
    */
    function defineReactive(obj, key, val, customSetter) {

    // get property descriptor (own or inherited!)
    var property = null;
    for (var proto = obj; !property && proto != Object.prototype; proto = Object.getPrototypeOf(proto)){
    property = Object.getOwnPropertyDescriptor(proto, key);
    }
    if (property && property.configurable === false) {
    return;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions