tnhu / jsface

Small, fast, elegant, powerful, and cross platform JavaScript OOP library. Support main(), singleton, super call, private, mixins, plugins, AOP and more.
MIT License
301 stars 46 forks source link

Nested objects extending #40

Open cranetm opened 7 years ago

cranetm commented 7 years ago

in jsface.extend-method nested objects instead of extending just replace each other. Example

var Man = Class({
    config: {
        prefix: 'Mr',
        name: '',
        eyes: 'green',
        hair: 'blonde',
        rightHanded: true
    },
    constructor: function (name) {
        this.config.name = name;
    },

    echo: function () {
        console.log(JSON.stringify(this.config));
    }
});

var Woman = Class(Man, {
    config: {
        prefix: 'Ms',
        eyes: 'blue'
    }
});
var jack = new Man("Jack");
jack.echo();
var rika = new Woman("Rika");
rika.echo();

and as a result we've got {"prefix":"Mr","name":"Jack","eyes":"green","hair":"blonde","rightHanded":true} {"prefix":"Ms","eyes":"blue","name":"Rika"} (name presents because of contructor)

In my opinion its incorrect behavior, all properties must inherit instead of whole object replacing, but only in case of simple objects (not for classes).