Undefined Method With Coffescript Using Html Event Onclick="function()"
I have this line of code in my html And My Coffescript editfunction = (id) -> console.log id return Why is it it returns ? Unc
Solution 1:
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()""