此代码传入一个函数,并没有继承我的EmployeesController对象的状态.如何将EmployessController对象绑定到焦点事件?
class @EmployeesController
constructor: (@dateInput) ->
@dateInput.focus(@searchInputGainedFocus)
searchInputGainedFocus: ->
console.debug @dateInput
Run Code Online (Sandbox Code Playgroud)
换句话说,当我给出dateInput焦点时,console.debug打印undefined.
我刚刚开始使用coffeescript看看所有的大惊小怪,我喜欢它.然而,在将我的旧脚本转换为咖啡时,我遇到了一个问题:
$(function() {
$(create_MP).keyup(function(e){
if(e.which == 16) {
isShift = false;
}
});
});
Run Code Online (Sandbox Code Playgroud)
那是我以前的JQuery,所以我试着把它变成coffeescript:
jQuery ->
$(create_MP).keyup(e) ->
if e.which == 16
isShift = false
Run Code Online (Sandbox Code Playgroud)
但是在打开控制台时出现此错误:
application.js:23Uncaught TypeError: Object [object Object] has no method 'keyUp'
有任何想法吗?
我不太确定CoffeeScript中不同变量的用途
class Cow
@utters = 1
constructor: (@name) ->
mutate:->
alert @utters
heads: 1
feet = 9
c = new Cow
Run Code Online (Sandbox Code Playgroud)
从我的调查来看,这似乎heads是公开的,feet是私人的.在搞清楚时name,我会感到困惑utters.因为name它或多或少地编译this.name = name并为utters它编译Cow.utters = 1.
所以我的问题是.它的范围utters和方式应该是什么?它的范围name和方式应该是什么?
我试图找出正确的行为,将多个回调串起来.
class Person
move_head: ->
head.animate({
left: x,
},{
complete: @move_foot,
});
move_foot: ->
foot.animate({
left: x,
},{
complete: @move_arm,
});
move_arm: ->
arm.animate({
left: x,
},{
complete: something_else,
});
Run Code Online (Sandbox Code Playgroud)
现在的问题是,头部动画很好,这称之为脚.脚也很好动画.问题是当脚完成时,它不会使手臂动起来.我无法弄清楚问题可能是什么.我猜测它可能与范围问题有关.
如何在CoffeeScript中编写for for循环?
for(i = cc.length - 2,i> = 0,i - = 2)
我正在尝试编写一个相当简单的"全选"功能,但我的javascript出错了.代码很简单,所以我只是发布它:
(function() {
$(function() {
var all_check_box;
all_check_box = '#tournament_league_127';
return $(all_check_box).change(function() {
return $('.leagueCheckBox').each(function() {
return this.prop("checked", true);
});
});
});
}).call(this);
Run Code Online (Sandbox Code Playgroud)
此代码由以下CoffeeScript生成:
$ ->
all_check_box = '#tournament_league_127'
$(all_check_box).change ->
$('.leagueCheckBox').each ->
this.prop("checked", true)
Run Code Online (Sandbox Code Playgroud)
但是,当我点击#tournament_league_127时,我收到以下错误:this.prop is not a function.我不确定我做错了什么.任何帮助,将不胜感激.
我有一个show动作,并希望在完成加载后调用一个函数.该函数依赖于正在加载的jQuery以及application.js的其余部分.
我尝试创建show.js.coffee,其中包含:
SomeClass.doSomething '<%= @thing.description %>'
Run Code Online (Sandbox Code Playgroud)
...但show.js.coffee从未加载,因此从未执行过.我该怎么做呢?
目前,我正在尝试在我的计算机上安装CoffeeScript.我有node.js版本0.6.7和npm 1.1.0-beta-10.当我运行命令npm install -g coffee-script时,它会显示此错误.
npm http GET https://registry.npmjs.org/coffee-script
npm http 200 https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/coffee-script/-/coffee-script-1.2.0.tgz
npm http 200 https://registry.npmjs.org/coffee-script/-/coffee-script-1.2.0.tgz
npm ERR! Could not create /usr/local/lib/node_modules/___coffee-script.npm
npm ERR! error installing coffee-script@1.2.0
npm ERR! Error: EACCES, permission denied '/usr/local/lib/node_modules/___coffee-script.npm'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR!
npm ERR! System Darwin 11.0.1
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "coffee-script"
npm ERR! cwd /Users/Solomon …Run Code Online (Sandbox Code Playgroud) 我正在用Coffee Script编写一个摇滚纸剪刀游戏,代码没有像我期望的那样编译.
CoffeeScript的
if choice is opponent_choice then alert "Tie!"
Run Code Online (Sandbox Code Playgroud)
编译成
if (choice === opponent_choice) alert("Tie!");
Run Code Online (Sandbox Code Playgroud)
但我在期待
if (choice === opponent_choice) {
alert("Tie!");
}
Run Code Online (Sandbox Code Playgroud)
我需要改变什么才能按照我的预期进行编译?
我在coffe脚本中有一个数组数组.如何以简单的方式将其转换为字符串然后返回到数组?所以我期待这样.使用eval在ruby中很容易做到.如何在coffe脚本中实现这一点?提前致谢.
"[[2,3,4],[2,3,4],[4,6,7]]" =>string
and then [[2,3,4],[2,3,4],[4,6,7]] back to an array again
Run Code Online (Sandbox Code Playgroud)