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

Extension methods don't need to be static #57

Open
Suor opened this issue Oct 8, 2015 · 0 comments
Open

Extension methods don't need to be static #57

Suor opened this issue Oct 8, 2015 · 0 comments

Comments

@Suor
Copy link

Suor commented Oct 8, 2015

It could be done dynamically like:

let String.prototype.reverse = function (...) {...};

'abc'.reverse()
getString().reverse()

In second example JavaScript implementation can't know statically whether getString() will return string, but it will now when it will get to it. This is actually better than :: cause you can polymorph:

let String.prototype.reverse = function (...) {...};
let Array.prototype.reverse = function (...) {...};
// ...
something.reverse()

The key idea is that extension is lexically scoped so that it won't affect any random code. Also, you most surely will want to import/export this extensions so my primitive syntax might not work, but this is only syntax issue.

There are actually a corresponding feature in ruby 2.0 and a perl module for this.

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