开发者

Javascript to Coffeescript conversion

开发者 https://www.devze.com 2023-03-09 14:09 出处:网络
Being not the best with javascript I am converting my file to coffeescript. Here is my original JS function makeTall(){

Being not the best with javascript I am converting my file to coffeescript.

Here is my original JS

function makeTall(){ 
    jQuery(this).find('ul:first').slideDown(
        {queue:false, duration:220}
    );
}

I have tried the following.

makeTall ->
    jQuery(@开发者_如何学C).find('ul:first').slideDown
        queue:false
        duration:220

Which produces.

makeTall(function() {
  return jQuery(this).find('ul:first').slideDown({
    queue: false,
    duration: 220
  });
});

The new style just confuses me a little and wanted to ask is this correct ?

I also tried.


You're simply missing the = sign before the function literal:

makeTall = ->
    jQuery(@).find('ul:first').slideDown
        queue:false
        duration:220


You might find this project to be helpful

https://github.com/rstacruz/js2coffee/

For your above case it produces:

makeTall = ->
  jQuery(this).find('ul:first').slideDown
    queue: false
    duration: 220
0

精彩评论

暂无评论...
验证码 换一张
取 消