在CoffeeScript的私人会员? [英] Private members in CoffeeScript?
本文介绍了在CoffeeScript的私人会员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在CoffeeScript中创建私有,非静态成员?目前我正在这样做,它只是使用一个公开的变量,以下划线开头,以澄清它不应该在类外使用:
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 clarify that it shouldn't be used outside of the class:
class Thing extends EventEmitter
constructor: (@_name) ->
getName: -> @_name
将变量放入类中使其成为静态成员, -静态的?
Putting the variable in the class makes it a static member, but how can I make it non-static? Is it even possible without getting "fancy"?
推荐答案
甚至可能没有花哨
Is it even possible without getting "fancy"?
很难说,你必须要 。
class Thing extends EventEmitter
constructor: (name) ->
@getName = -> name
请记住,这只是JavaScript。
Remember, "It's just JavaScript."
这篇关于在CoffeeScript的私人会员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文