开始使用 Backbone 和 CoffeeScript [英] Get started with Backbone and CoffeeScript

查看:16
本文介绍了开始使用 Backbone 和 CoffeeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这更像是一个 CoffeeScript 问题.我希望能够在 foo.coffee 中使用来自 Backbone 的类文件.我尝试使用 -r 选项在运行 时要求 Backbone>咖啡命令:

I think this is more of a CoffeeScript question. I want to be able to use classes from Backbone in a foo.coffee file. I tried using the -r option to require Backbone when running the coffee command:

coffee -r "../backbone" -c foo.coffee

编译器抱怨 Backbone 未定义.我相信这一定很简单.很容易找到使用 CoffeeScript主干在一起.我还尝试像这样要求文件顶部的类:

The compiler complained that Backbone was undefined. I'm sure that this must be pretty simple. It's easy to find examples of people using CoffeeScript and Backbone together. I also tried requiring the class at the top of the file like so:

Backbone.model = require('../../backbone').Model

class foo extends Backbone.model

我可以在 initialize 方法中将其写入 console.log.当我尝试将 this 写入 console.log 时,我得到了一个空对象 {}.

I could write it to console.log in the initialize method. When I tried writing this to console.log, I just got an empty object {}.

谁能告诉我怎么做?

推荐答案

如果你使用 CoffeeScriptBackbone.js,我推荐查看 早午餐.它可能会让你克服困难.

If you're using CoffeeScript and Backbone.js, I recommend checking out Brunch. It may just get you past your difficulties.

这篇关于开始使用 Backbone 和 CoffeeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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