Skip to content Skip to sidebar Skip to footer

Undefined Method With Coffescript Using Html Event Onclick="function()"

Solution 1:

Coffeescript will wrap all files in an anonymous function which is immediately executed. This means all variables you define are locally scoped unless explicitly placed in the global namespace (in browsers it is the window object, while in NodeJS it's global).


From coffeescript.org (talking about using Coffeescript in a browser, but it also applies to using the Coffeescript compiled to JS ):

The usual caveats about CoffeeScript apply — your inline scripts will run within a closure wrapper, so if you want to expose global variables or functions, attach them to the window object.


Try changing your Coffeescript to:

window.editfunction = (id) ->
  console.log id

This will expose the function globally on the window object so that it can be used within an onclick handler.

Solution 2:

@editfunction = editfunction = (id) ->
    console.log 'Yeheyyy'

this will works :)

Post a Comment for "Undefined Method With Coffescript Using Html Event Onclick="function()""