当我从一些教程中学习 CoffeeScript 时,我喜欢使用http://jsfiddle.net/进行测试。我想注释掉多行。所以我点击我的 Mac cmd+ /,在大多数编辑器中,这与注释掉选择有关。在 JSFiddle 中,我在语言部分设置了咖啡脚本,<!--而-->不是#在每一行上设置。
是否有其他组合键可以注释掉选择?
由于某些原因它不起作用(在coffeescript中)
afunction = () ->
window.clearTimeout(timeoutID)
$(".x").text("#{message}").addClass("y")
timeoutID = window.setTimeout (->
$(".x").removeClass("y")
), 4000
Run Code Online (Sandbox Code Playgroud) myModule.search location, item, (err, data) ->
if err?
res.end 'Error!'
else
res.write 'got here'
partial 'partials/table', {items: data, layout: false}
res.end()
return
Run Code Online (Sandbox Code Playgroud)
我的服务器上出现以下错误:
partial('partials/table', {
^
ReferenceError: partial is not defined
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我正在用CoffeScript编写一个库(所以JS),这是一个繁重的数学..我真的需要使用类型数组(Float64Array)和它们提供的所有性能.
那么扩展类型化数组功能的最佳方法是什么?
目前我正在做功能:
Vector =
create: (ag...) ->
CGE2Point.create ag...
dot: (i,j) ->
i[0]*j[0] + i[1]*j[1]
add: (i,j) ->
@.create i[0]+j[0], i[1]+j[1]
sub: (i,j) ->
@.create i[0]-j[0], i[1]-j[1]
mul: (s,v) ->
@.create s * v[0], s * v[1]
div: (s,v) ->
@.create v[0] / s, v[1] / s
Run Code Online (Sandbox Code Playgroud)
但是拥有一个继承自类型化数组的Vector对象会非常好.我知道这个方法:
class Vector extends Float64Array
Run Code Online (Sandbox Code Playgroud)
创建一个没有类型化数组的全部好处的类关于子类化数组的问题,阅读以下文章Dean Edwards建议从iframe获取对象副本,这个其他参考以其他方式做对不起Dean.但是类型化数组没有所有方法.
那么,如何正确(或至少最优雅和最佳)子类化类型化数组?或者我应该写所有类似的功能?
我有一个Flot图表,x轴显示时间 - 刻度大小等于一天.我正在显示在一天中的不同时间发生的事件的持续时间,并且我想将它们堆叠起来.Flot的时间模式根据毫秒来定位条形图,因此条形图在每个刻度/日中分开.是否有一种快速的方法使条形堆叠起来,防止它们在每天的不同x位置被绘制?
我正在尝试使用coffescript和jquery进行ajax调用并使用结果更新表单输入类型,但我的输入更新了[object XMLDocument]而不是返回文本
这是我使用的coffescript代码.
$ ->
$('#get-mac').live 'click', (e) =>
e.preventDefault()
podaci = {broj : $('#contract_no').val(), action : 'get-mac-ua'}
$.ajax '/hhh'
type: 'POST'
data: podaci
datatype: 'text'
success: (data) ->
if data == 'False'
$('#mac').removeAttr "readonly"
alert 'Ne postoji MAC adresa na UA, upiši ru?no'
else
$('#mac').val data
$('#mac').removeAttr "readonly"
$('#contract_no').attr "readonly", true
Run Code Online (Sandbox Code Playgroud)
这是旧的js版本,有效
$(document).ready(function(){
$("#get-mac").live('click', function(e){
e.preventDefault();
var podaci = {broj : $('#contract_no').val(), action : 'get-mac-ua'};
$.ajax({
type: "POST",
url: '/hhh',
data: podaci,
dataType: 'html',
success: function(data){
if(data == "False") …Run Code Online (Sandbox Code Playgroud) 我是Coffeescript的新手,想在jquery 1.6.4中使用delegate()方法.方法签名是.delegate( selector, eventType, handler ).我如何在Coffeescript中调用此方法?我正在使用Rails 3.1.
谢谢,丹妮.
我有一个MapHandler类.
我创建了一个对象myMaphandler = new MapHandler并调用了initialize方法.但@ userLocationMarker.getPosition()返回null :(
如果我将评论提醒并从Chrome JS控制台调用@ userLocationMarker.getPosition(),我将获得必要的坐标.
class window.MapHandler
initialize: (centerLocation) ->
@makeMap(centerLocation)
@defineUserLocation()
alert @userLocationMarker.getPosition()
makeMap: (centerLocation) ->
myOptions =
zoom: 14
center: centerLocation
mapTypeId: google.maps.MapTypeId.ROADMAP
@map = new google.maps.Map(document.getElementById("map_canvas"), myOptions)
placeMarker: (location, icon_path) ->
if icon_path
markerImage = new google.maps.MarkerImage(icon_path, null, null, null, new google.maps.Size(25, 25))
else
markerImage = null
marker = new google.maps.Marker(
position: location
map: @map
icon: markerImage)
defineUserLocation: () ->
@userLocationMarker = @placeMarker(null, null)
handleMap = (position) =>
pos = new google.maps.LatLng(position.coords.latitude, …Run Code Online (Sandbox Code Playgroud) 说我有一些CoffeeScript中(与Underscore.js混合)是这样的:
someData =
hello: 'haha'
_(3).times (index) ->
someData["key-#{index}"] = index
Run Code Online (Sandbox Code Playgroud)
someData那么价值将是:
hello: 'haha'
key-0: 0
key-1: 1
key-2: 2
Run Code Online (Sandbox Code Playgroud)
如果Coffeescript有一些语法糖允许我写这样的东西会很好:
someData =
hello: 'haha'
<%
_(3).times (index) ->
%>
key-#{index}: index
Run Code Online (Sandbox Code Playgroud)
这将产生someData其价值与原始价值相同的价值.
Coffeescript有这样的设施吗?
我试图处理一个简单的案例,我可以得到一个对象,或一个字典.所以我要么得到一个像这样的对象:
obj.fields.nick
Run Code Online (Sandbox Code Playgroud)
或者它将成为一本字典
obj['nick']
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更简单的方法来执行以下操作:
value = (eval("obj.fields." + field[1]) if obj?.fields ) ? eval("obj['#{field[1]}']")
Run Code Online (Sandbox Code Playgroud)
我希望做的事情如下:
value = (obj?.fields?."#{field[1]}" ) ? eval("obj['#{field[1]}']")
Run Code Online (Sandbox Code Playgroud)
但如果有效,我不会写这篇文章......
我基本上是在寻找一种方法来执行字符串作为if的一部分