theLucre
theLucre

Reputation: 121

CoffeeScript callback parameter becomes Object

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?

Upvotes: 0

Views: 853

Answers (1)

Tanzeel Kazi
Tanzeel Kazi

Reputation: 3827

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

Upvotes: 1

Related Questions