coffeescript中类似python的字符串插值
我有这样一个错误的名称空间coffeescript中类似python的字符串插值,python,string,coffeescript,string-interpolation,language-comparisons,Python,String,Coffeescript,String Interpolation,Language Comparisons,我有这样一个错误的名称空间 errorMessages= error404Find: "Hosts not found" error404FindByHost: "Host - #{hostName} - not found" error400: "No host" 主机名应分配给null,并在如下函数中覆盖: this.hostName = 'smth' 或者我可以在python中使用类似的东西: errorMessages= {'error404Find': "Hosts
errorMessages=
error404Find: "Hosts not found"
error404FindByHost: "Host - #{hostName} - not found"
error400: "No host"
主机名应分配给null,并在如下函数中覆盖:
this.hostName = 'smth'
或者我可以在python中使用类似的东西:
errorMessages=
{'error404Find': "Hosts not found"
'error404FindByHost': "Host - {hostName} - not found"
'error400': "No host"}
errorMessages['error404FindByHost'].format(hostName='smth')
您可以将所有这些条目设置为函数,然后使用参数对其应用字典:
errorMessages=
error404Find:-> "Hosts not found"
error404FindByHost:-> "Host - #{@hostName} - not found"
error400:-> "No host"
alert errorMessages["error404FindByHost"].apply hostName:"host1"