如何从其他资产Coffescript访问功能? [英] How can Coffescript access functions from other assets?

查看:86
本文介绍了如何从其他资产Coffescript访问功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有两个控制器,酒店视频。我希望 hotels.js.coffee 能够访问 videos.js.coffee 中创建的函数,但我得到一个未定义的错误。

So I have two controllers, hotels and videos. I want the hotels.js.coffee to be able to access functions created in videos.js.coffee but I get a "is not defined" error.

我是CoffeeScript的新人,所以任何线索都会感激。

I'm new to CoffeeScript so any clues would be appreciated.

推荐答案

CoffeeScript会将窗口(function {})的范围内的自动执行函数中的JS编译为JS:call(this);

CoffeeScript will compile your coffee to JS wrapped in a self-executing function with the scope of the window (function{}).call(this);

所以在videos.js.coffee中你可以写如下:

So in videos.js.coffee you can write something like:

    @getVideo: (id) ->

,getVideo函数将绑定到窗口对象。

and the getVideo function will be bound to the window object.

这篇关于如何从其他资产Coffescript访问功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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