locked
Defining functions in javascript

    Question

  • Hi all!!

    I've just begun studying javascript for Windows 8, but I'm stuck when defining functions:

    In code samples, I have:

    function myFunction() {...}

    But I do want to use this syntax:

    var myFunction = function() {...}

    (The reason why I want to use this syntax is because I use Coffeescript)

    For an unknown reason, the second syntax makes occur errors ("JavaScript runtime error: Object expected"). Does anyone know why or know a workaround?

    Thanks!

    Friday, August 31, 2012 9:32 AM

Answers

  • My mistake !!

    In fact, the syntax myFunction = function() { return true }; requires to define the function before it is called while the other syntax just doesn't care. I was stupidly translating a sample code so I wasn't careful about what I was writing.

    No bug after all.

    • Marked as answer by N-Studio Friday, August 31, 2012 1:26 PM
    Friday, August 31, 2012 1:26 PM