CoffeeScript 是否能将函数写在调用时的下面?
正常情况下,都是这样写:
sayHi = (myName) ->
console.log 'Hi, ' + myName
sayHi 'Jack'
因为会编译成
var sayHi;
sayHi = function(myName){
return console.log('Hi, ' + myName);
}
sayHi('Jack');
所以如果写成下面那样,是会报
undefined
的:
sayHi 'Jack'
sayHi = (myName) ->
console.log 'Hi, ' + myName
但是我个人喜欢将函数写在后面,调用写在前面,就像
sayHi('Jack');
function sayHi(myName){
return console.log('Hi, ' + myName);
}
不知道是否有可能实现?
JUNDAM
10 years, 1 month ago