如何将此CoffeeScript函数转换为类,以便私有成员可以访问公共成员?
MyClass= ->
prVar = 'private'
prMethod1 = ->
console.log 'prMethod'
self.pubMethod2()
public_members =
pubVar : 'public'
pubMethod1: ->
console.log 'pubMethod1'
prMethod1()
pubMethod2: ->
console.log 'pubMethod2'
return public_members
my = new MyClass()
my.pubMethod1()
类MyClass ??
答案 0 :(得分:0)
我希望以下代码可以帮助您:
@MyClass= ->
prVar = 'private'
prMethod1 = ->
console.log 'prMethod'
public_members.pubMethod2()
public_members =
pubVar : 'public'
pubMethod1: ->
console.log 'pubMethod1'
prMethod1()
pubMethod2: ->
console.log 'pubMethod2'
return public_members