Inheritance model

Models

const Inheritance_Child = Fractale.create("Inheritance_Child", {
    value: String
});

const Inheritance_Parent = Fractale.create("Inheritance_Parent", Inheritance_Child, {
    children: [
        Inheritance_Child
    ]
});

Run

const { Inheritance_Parent } = module.exports.get();
const instance = new Inheritance_Parent({
    value: 'Hello',
    children: [
        { value: 'world' },
        { value: 'you' },
    ]
});

_.test(instance.sayHelloTo(0), 'Hello world', `Expected "Hello world" got "${instance.sayHelloTo(0)}"`);
_.test(instance.sayHelloTo(1), 'Hello you', 'Error on parent method call');
_.test(instance.toUpperCase(), 'HELLO', 'Error on method inheritance');

resolve(instance);

Results

{
    "uuid": "095ee570-53b7-418e-856d-1cb869b7f8cd",
    "value": "Hello",
    "children": [
        {
            "uuid": "d01623e5-8c49-4fc9-b7a8-94ae79a87dff",
            "value": "world"
        },
        {
            "uuid": "2c54c27b-b05b-4344-9e49-29985e8b8383",
            "value": "you"
        }
    ]
}

Last updated