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

why a varargs/overloaded API? #37

Closed
leeoniya opened this issue Jul 9, 2019 · 2 comments
Closed

why a varargs/overloaded API? #37

leeoniya opened this issue Jul 9, 2019 · 2 comments

Comments

@leeoniya
Copy link

leeoniya commented Jul 9, 2019

hey @Riim,

why this

user.fullName('subscribe', function() {
    console.log('fullName: ' + this.fullName());
});

instead of this?

user.fullName.subscribe(function() {
    console.log('fullName: ' + this.fullName());
})

there could be better benefits for API discoverability, minification and performance by using separate instance methods instead of overloading the getter/setter functionality and relying on arg count.

what do you think?

@Riim
Copy link
Owner

Riim commented Jul 10, 2019

Hi,
done in v1.9.0

Previously, there were problems with it due to the impossibility of installing a prototype for functions:

let fn = function() {};
Object.setPrototypeOf(fn, {
    __proto__: Function.prototype,
    // ...
})

Rewrite a lot methods in the loop is not suitable, because it is slow:

let fn = function() {};
for (let name in methods) {
    fn[name] = methods[name];
}

Now, no problem. Also now possible to use with decorators: cellx-decorators.

@leeoniya
Copy link
Author

great, thanks!

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

2 participants