从jQuery函数调用coffeescript函数 [英] Call coffeescript function from jQuery function

查看:154
本文介绍了从jQuery函数调用coffeescript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件:第一个是一个普通的jQuery,第二个是Coffeescript

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

jQuery文件:

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

CoffeeScript档案:

CoffeeScript file:

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

我得到以下错误:未处理的错误:未定义的变量:checkPrice

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

在模板中,它们包含在相反的方向:coffeescript文件,然后是jquery文件。

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

有没有办法让他们一起工作?

Is there some way to make them working together ?

推荐答案

确定。 。

checkPrice应该被声明为全局的,因此在coffeescript文件中我有:

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

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

现在可以了!

每个人谁在那里帮助我反正。

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

这篇关于从jQuery函数调用coffeescript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆