Jeremie Ges
Jeremie Ges

Reputation: 2745

Get variable of a class out of the scope with coffeescript

I have that code :

class @Validator


  ##
  # Constructor
  #
  # Set basic variables
  #
  ##
  constructor: ->

    @_errors = {}

  ##
  # Errors
  ##
  errors:

    first: ->

    last: ->

    all: =>

      return @_errors 

    get: ->

In the method all() of the object errors it's impossible to reach the content of the variable _errors, how it's possible to reach it ?

Upvotes: 0

Views: 29

Answers (1)

Henrik Andersson
Henrik Andersson

Reputation: 47172

If the API you're after is this

validator = new Validator()
validator.errors.all()

then place the errors object within the constructor and also change

errors:
    first: ->

to

errors =
    first: ->

Otherwise, just change

errors:
    first: ->

to

errors: ->
    first: ->

making the API look like this validator.errors().all()

Upvotes: 1

Related Questions