简体   繁体   English

在Coffeescript中使用参数中的排除项

[英]Using exclusions in parameters in Coffeescript

I want to "refresh" parts of a website. 我想“刷新”网站的某些部分。 I want to make a function where all of the parts will be refreshed except for those passed in the parameters. 我想创建一个函数,除了在参数中传递的部分之外,所有部分都将被刷新。 I am using a splat for the parameter, but I am stuck after that. 我正在使用splat作为参数,但之后我被卡住了。 Here is the code so far: 这是迄今为止的代码:

refresh = (exceptions...) ->
    $("#playersTotalHealth").text("Health: #{player.totalHealth}")
    $("#playersHealth").text("Your Health: #{player.currentHealth}/#{player.totalHealth}")
    $("#opponentsHealth").text("Enemy's Health: #{e1.currentHealth}/#{e1.Health}")
    ...

If I only wanted to refresh #playersTotalHealth then how can I use exceptions... to do that? 如果我只想刷新#playersTotalHealth那么我该如何使用exceptions...来做到这一点?

This is more like a problem with the execution logic itself... You can just check if an item is present in the exceptions array: 这更像是执行逻辑本身的问题......你可以检查exceptions数组中是否存在一个项:

# Not in the exceptions array, execute...
if "#playersTotalHealth" not in exceptions then $("#playersTotalHealth").text "Health: #{player.totalHealth}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM