我正在尝试实现一些无法从客户端调用的私有方法,通过在Meteor.methods范围之外定义它们,并在服务器文件夹下
我有这个
Meteor.methods
#
# Generates a random event based on tags
#
generateRandomEventForCharacter: (characterId) ->
character = Characters.findOne(characterId)
rarity = randomRarity()
# Tags
locationTags = ['all', character.location]
alignmentTags = character.alignmentTags
characterTags = character.characterTags
event = Events.findOne( $and: [
locationTags: { $all: locationTags },
alignmentTags: { $all: alignmentTags },
characterTags: { $all: characterTags }
])
return event
#
# Random rarity
#
randomRarity: () ->
random = Math.random()
rarity = switch
when random < 0.005 then 'mythical'
when random < 0.050 then 'epic'
when random < 0.100 then 'rare'
when random < 0.250 then 'uncommon'
else 'common'
但不知何故抛出以下异常
Exception while invoking method 'generateRandomEventForCharacter' ReferenceError: randomRarity is not defined
答案 0 :(得分:1)
randomRarity:
应为randomRarity =
。几天前犯了同样的错误:)