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

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

问题描述

所以我有两个控制器,hotelsvideos.我希望 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 会将你的咖啡编译成 JS,封装在一个具有窗口范围的自执行函数中 (function{}).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天全站免登陆