Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ._defineMethod to add method class protoype? #110

Closed
mStirner opened this issue Apr 12, 2022 · 0 comments
Closed

Change ._defineMethod to add method class protoype? #110

mStirner opened this issue Apr 12, 2022 · 0 comments

Comments

@mStirner
Copy link
Member

Check if ._defineMethod add methods/properties to the component class. (Should not be the case)
If so, change the behaviour to patch the method/property to the class protoype?

    _defineMethod(name, worker) {
        Object.defineProperty(Object.getPrototypeOf(this), name, {
            enumerable: false,
            configurable: false,
            writable: false,
            value: worker
        });
    }
class Base {
    constructor() {

    }
}

class Common extends Base {

    constructor() {
        super();
    }

    _defineMethod(name, worker) {
        Object.defineProperty(Object.getPrototypeOf(this), name, {
            enumerable: false,
            configurable: false,
            writable: false,
            value: worker
        });
    }

}


class Component extends Common {
    constructor() {

        super();

        this._defineMethod("method1", () => { console.log("method1"); });
        this._defineMethod("method2", () => { console.log("method2"); });
        this._defineMethod("method3", () => { console.log("method3"); });

    }
}

class C_COMP extends Component {
    constructor() {
        super();
    }
}

const c = new C_COMP();

console.log(c.method1())

"Bad" implementation:

    _defineMethod(name, worker) {
        //Object.getPrototypeOf(this)
        Object.defineProperty(this, name, {
            enumerable: false,
            configurable: false,
            writable: false,
            value: worker
        });
    }
@mStirner mStirner added this to the v3.0.0 release milestone Oct 29, 2022
@mStirner mStirner mentioned this issue Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant