Monday, May 20, 2024
164
rated 0 times [  167] [ 3]  / answers: 1 / hits: 16996  / 12 Years ago, tue, june 19, 2012, 12:00:00

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. 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) ->  
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.



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');
}
}
});
}

More From » coffeescript

 Answers
2

What you have here is not a function named freeSample. Is an anonymous function with a single argument called freeSample. The syntax for functions in CoffeeScript is like this:



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:



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. There is an (awesome) online tool for converting between js/coffeescript and can be found here: http://js2coffee.org/



The above snippet generated by this tool.


[#84810] Monday, June 18, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;