0

I'm trying to put a function within an object in CoffeeScript however when printing the function I get the actual function and not what I've asked it to return.

I am currently learning CoffeeScript so please excuse me if this is a really silly mistake :)

Here is my code:

define =
    hello: ->
        Swordling = true
        user = "Swordling" if Swordling
        return user
alert define.hello

And here is the result I get: http://prntscr.com/8wzi6f

1 Answer 1

1

Well, yes, you're only outputting the function, you're not calling the function:

alert define.hello()
Sign up to request clarification or add additional context in comments.

2 Comments

Ohhh! Thank you so much! I didn't think the () was necessary in CoffeeScript. :)
It is only optional when it's unambiguous by the context whether you're calling the function or just referring to the function. foo bar is unambiguously foo(bar), however foo could be both foo or foo(), and it defaults to the former.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.