[英]CoffeeScript function argument
I have a function that I want to pass an argument, market, to the function freeSample, but I can't seem to get it set as an argument. 我有一个函数,我想将一个参数,市场,传递给函数freeSample,但我似乎无法将它设置为参数。 Please take a moment to look at my code and help me to understand how to get the market as an argument in the freeSample function. 请花点时间查看我的代码并帮助我了解如何在freeSample函数中将市场作为参数。
(freeSample) ->
market = $('#market')
jQuery('#dialog-add').dialog =
resizable: false
height: 175
modal: true
buttons: ->
'This is Correct': ->
jQuery(@).dialog 'close'
'Wrong Market': ->
market.focus()
market.addClass 'color'
jQuery(@).dialog 'close'
UPDATE: Here is the JavaScript I currently have that I am trying to convert to CoffeeScript. 更新:这是我目前正在尝试转换为CoffeeScript的JavaScript。
function freeSample(market)
{
var market = $('#market');
jQuery("#dialog-add").dialog({
resizable: false,
height:175,
modal: true,
buttons: {
'This is Correct': function() {
jQuery(this).dialog('close');
},
'Wrong Market': function() {
market.focus();
market.addClass('color');
jQuery(this).dialog('close');
}
}
});
}
What you have here is not a function named freeSample
. 你在这里拥有的不是一个名为freeSample
的函数。 Is an anonymous function with a single argument called freeSample
. 是一个带有单个参数的匿名函数,名为freeSample
。 The syntax for functions in CoffeeScript is like this: CoffeeScript中函数的语法如下:
myFunctionName = (myArgument, myOtherArgument) ->
So in your case it could be something like this: 所以在你的情况下它可能是这样的:
freeSample = (market) ->
#Whatever
EDIT (after OP updated the question): In your specific case you could do it like so: 编辑 (OP更新问题后):在您的具体情况下,您可以这样做:
freeSample = (market) ->
market = $("#market")
jQuery("#dialog-add").dialog
resizable: false
height: 175
modal: true
buttons:
"This is Correct": ->
jQuery(this).dialog "close"
"Wrong Market": ->
market.focus()
market.addClass "color"
jQuery(this).dialog "close"
PS. PS。 There is an (awesome) online tool for converting between js/coffeescript and can be found here: http://js2coffee.org/ 有一个(很棒的)在线工具可以在js / coffeescript之间进行转换,可以在这里找到: http ://js2coffee.org/
The above snippet generated by this tool. 以上代码段由此工具生成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.