Skip to content

Initializing protocol fields #35

@benash

Description

@benash

Hi, thanks for your work on this interesting proposal. Would be possible to initialize a protocol field by accessing this, or would that need to be a method? E.g.:

protocol Pageable {
  pageSize
  items

  getFirstPage() {
    return this[Pageable.items].slice(0, this[Pageable.pageSize])
  }
}

class GroceryList {
  constructor(items) {
    this.items = items
  }
  implements protocol Pageable {
    pageSize = 2
    items = this.items                // <-- Would this be legal?
    get items() { return this.items } // <-- Or this?
    items() { return this.items }     // <-- Or would this be the only way to go?
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions