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

Feature/class traits #130

Merged
merged 7 commits into from
Nov 5, 2023
Merged

Feature/class traits #130

merged 7 commits into from
Nov 5, 2023

Conversation

kaidesu
Copy link
Member

@kaidesu kaidesu commented Nov 3, 2023

What does this implement or fix?

This update brings in the ability to define and use class traits. Class traits are a means to reduce code duplication by creating and sharing reusable methods and properties through traits. Classes may then use any number of these traits as if they were part of the class itself.

Added

  • Added trait expression
  • Added use statement

Here's a very simple example:

trait Loggable {
  function logError(message) {
    console.log('Error: ' + message)
  }

  function logWarning(message) {
    console.log('Warning: ' + message)
  }
}
import Loggable from 'loggable'

class Player {
  use Loggable

  function debug() {
    this.logWarning('DEBUG')
    
    ...
  }
}

@kaidesu kaidesu marked this pull request as ready for review November 5, 2023 00:06
@kaidesu kaidesu merged commit 6f451da into 1.0 Nov 5, 2023
1 check passed
@kaidesu kaidesu deleted the feature/class-traits branch November 5, 2023 00:07
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

Successfully merging this pull request may close these issues.

None yet

1 participant