1

I have this bit of Coffeescript

d3Graph: =>

  refreshData: ->
    console.log "refresh data called"

  someButton.click ->
    refreshData()

When I click "someButton" I receive an error

Uncaught ReferenceError: refreshData is not defined 

Anyone see my error?

1
  • 2
    Always always checkout the compiled output. When you do that, the problem usually becomes somewhat obvious. Commented Nov 20, 2012 at 20:15

2 Answers 2

3

Try using refreshData = instead of refreshData: here.

d3Graph: =>

  refreshData = ->
    console.log "refresh data called"

  someButton.click ->
    refreshData()

If that doesn't work, you'll have to provide more complete code.

If you run into problems like this, it's always helpful to see what the output JavaScript is.

For instance, in this case, your original code outputs:

var _this = this;

({
  d3Graph: function() {
    ({
      refreshData: function() {
        return console.log("refresh data called");
      }
    });
    return someButton.click(function() {
      return refreshData();
    });
  }
});

So it should be apparent that there is no variable/function called refreshData!

Sign up to request clarification or add additional context in comments.

Comments

0

Jamie Wong explains it correctly. I was just wondering if you were trying to use d3Graph as a class:

class d3Graph

  @refreshData: ->
    console.log "refresh data called"

someButton.click ->
  d3Graph.refreshData()

or when the graph is an instance:

class d3Graph

  refreshData: ->
    console.log "refresh data called"

graph = new d3Graph()

someButton.click ->
  graph.refreshData()

Hope this helps.

1 Comment

Hey, I'm not creating a class but thanks for the suggestion. I'm still learning coffeescript (obviously), I'm sure I'll make a class sometime soon and use what you suggested. :)

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.