-1

I thought of a syntax that could be very helpful :

function myFunction(){}
myFunction(){anotherFunction();};

I want to have the same result as : http://jsfiddle.net/tMawX/ but a syntax like : http://jsfiddle.net/J9hQp/

Is there a way to do it?

My final goal is to re-write the for function so it is wrote like that : for(0,100){func}; instead of for(0,100,func);

4

1 回答 1

1

CoffeeScript 具有简短的函数语法:

eatMe = (x)-> x(); alert(3);

eatMe -> alert(2)

翻译为:

var eatMe;

eatMe = function(x) {
  x();
  return alert(3);
};

eatMe(function() {
   return alert(2);
});

你的for函数看起来像:

myfor = (from, to) ->
    (callback) ->
        [callback(i) for i in [from..to]]

myfor(1, 3) -> alert('Hooray!')
于 2012-05-22T17:49:49.807 回答