0

My callback function is being wrapped as an object when process into JavaScript. The browser throws this error because of it:

Uncaught TypeError: object is not a function

The CoffeeScript:

startCamera: ->
    @media = $('#camera').getUserMedia {},
    success: (obj) ->
        console.log obj
        return
return

The Output:

startCamera: function() {
    this.media = $('#camera').getUserMedia({}, {
        success: function(obj) {
            console.log(obj);
        }
    });
}

How can I build a regular anonymous function for the parameter?

1 Answer 1

1

If I have understood your question correctly you want to pass an anonymous function as the second parameter.

To do that you will need to get rid of the text success: so that your coffeescript looks as follows:

startCamera: ->
    @media = $('#camera').getUserMedia {},
    (obj) ->
        console.log obj
        return
    return
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect! For readability, is there any way to name anonymous functions inline , or does it need to be declared before it's passed in?
@theLucre if readability is a concern you could always add a coffeescript comment above the function like # success:.

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.