Call coffeescript function from jQuery function

倖福魔咒の 提交于 2019-12-12 05:42:36

问题


I have two files: first one is a plain jQuery, and a second one is a Coffeescript

jQuery file:

$(document).ready(function(){
    checkPrice();
});

CoffeeScript file:

$ ->
   checkPrice = ->
     alert("OK");

I get following error: "Unhandled Error: Undefined variable: checkPrice"

In the template they are included in opposite direction: coffeescript file, then jquery file.

Is there some way to make them working together ?


回答1:


OK. Got it.

checkPrice should have been declared as global, so in coffeescript file I have:

window.checkPrice =->
  alert("OK");

And now it works!

Thank's everyone who was there to help me anyway.



来源:https://stackoverflow.com/questions/13604175/call-coffeescript-function-from-jquery-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!