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 supporting? #41812

Closed
acasta-yhliu opened this issue Dec 4, 2020 · 1 comment
Closed

Extension Methods supporting? #41812

acasta-yhliu opened this issue Dec 4, 2020 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@acasta-yhliu
Copy link

What about supporting c# style extension method? Syntax should be like

class MyClass {
  public myClassId: number;
  constructor() {
    this.myClassId = 2;
  }
}

// extend the class by using c# like syntax
class ExtendMyClass {
  public static DisplayMyClassId(this myClass: MyClass) {
    console.log(myClass.myClassId);
  }
}

// or just dont use the a class to extend it, just use a function
function DisplayMyClassId(this myClass: MyClass) {
  console.log(myClass.myClassId);
}

I actually prefer the latter one, implementing this should be easy to translate to js since js provide with prototype, export keyword also work with this kind. It would be great if supporting this kind of syntax to use functional programming, like extend a method for a defined type.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Dec 4, 2020
@RyanCavanaugh
Copy link
Member

See #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants