我目前正在使用以下代码进行比较,但如您所见,我正在制作大量的 if else 语句。有没有办法简化代码并提高效率?
getGenderRef: (grammer=nil) ->
@gender_ref = ""
gender = this.get('gender')
if gender? and gender == 'male'
if grammer == 'he'
@gender_ref = 'he'
else if grammer == 'his'
@gender_ref == 'his'
else if grammer == 'him'
@gender_ref == 'him'
else if gender? and gender == 'female'
if grammer == 'he'
@gender_ref = 'she'
else if grammer == 'his'
@gender_ref == 'her'
else if grammer == 'him'
@gender_ref == 'her'
else if gender? or gender == null
if grammer == 'he'
@gender_ref = 'he/she'
else if grammer == 'his'
@gender_ref == 'his/her'
else if grammer == 'him'
@gender_ref == 'him/her'