I am having trouble assigning function return value to variable. Why do I get the function returned instead of the final product when I log it to console?
time = ->
today = new Date()
minutes = today.getMinutes()
if minutes < 10 then minutes = "0#{minutes}"
hours = today.getHours()
if hours < 10 then hours = "0#{hours}"
"#{hours}:#{minutes}"
console.log time
Simply add do
to execute the function (if you expect "time" to contain the string, not the function):
time = do ->
or use "time" as a function, ie, invoke it:
console.log time()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.