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

Add support for static methods #16

Open
wiseodd opened this issue Jul 13, 2024 · 0 comments
Open

Add support for static methods #16

wiseodd opened this issue Jul 13, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@wiseodd
Copy link
Owner

wiseodd commented Jul 13, 2024

Use the class keyword preceding the method to indicate a static method that hangs off the class object.

class Math {
  class square(n) {
    return n * n;
  }
}

print Math.square(3); // Prints "9".

The “metaclasses” used by Smalltalk and Ruby are a particularly elegant approach. Hint: Make LoxClass extend LoxInstance and go from there.

@wiseodd wiseodd added the enhancement New feature or request label Jul 13, 2024
@wiseodd wiseodd self-assigned this Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant