Private members in CoffeeScript?

后端 未结 11 2036
太阳男子
太阳男子 2020-12-12 13:37

Does somebody know how to make private, non-static members in CoffeeScript? Currently I\'m doing this, which just uses a public variable starting with an underscore to clari

11条回答
  •  失恋的感觉
    2020-12-12 14:10

    Here is how you can declare private, non-static members in Coffeescript
    For full reference, you can take a look at https://github.com/vhmh2005/jsClass

    class Class
    
      # private members
      # note: '=' is used to define private members
      # naming convention for private members is _camelCase
    
      _privateProperty = 0
    
      _privateMethod = (value) ->        
        _privateProperty = value
        return
    
      # example of _privateProperty set up in class constructor
      constructor: (privateProperty, @publicProperty) ->
        _privateProperty = privateProperty
    

提交回复
热议问题