Skip to content

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
@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.

2 participants