标签: coffeescript

CoffeeScript - 将args传递给超级构造函数的问题

我有以下CoffeeScript代码:

planet = new Planet p5, {x: 100, y: 100, diameter: 20}
Run Code Online (Sandbox Code Playgroud)

和其他地方:

class GameObject
  constructor: (@p5, @x, @y) ->
    @selected = false

class Planet extends GameObject
  constructor: (p5, opts) ->
    super (p5 opts.x opts.y)
    @diameter = opts.diameter
Run Code Online (Sandbox Code Playgroud)

而对于super它说的线:

未捕获的TypeError:对象#<Object>的属性"x"不是函数

当它只是:它是好的:

class Planet
  constructor: (p5, opts) ->
    @x = opts.x
    @y = opts.y
    @diameter = opts.diameter
    @selected = false
Run Code Online (Sandbox Code Playgroud)

即在让它成为一个更通用的孩子之前GameObject...我已经尝试了一些重新安排以使其工作,但所有都保留.不确定它是否与CoffeeScript或JavaScript有关.官方网站上的"尝试CoffeScript"事情在这里没有发现任何错误.浏览器是Chrome ...这里有什么问题,我该如何克服这个问题?

javascript coffeescript

0
推荐指数
1
解决办法
1345
查看次数

骨干,nodejs等概述

有人能给我一个鸟瞰主干,nodejs等.

这些不同的技术/框架如何结合在一起.

意思是,如果我使用nodejs,我是否必须使用骨干?

那么cofeescript,它与骨干有什么关系?

node.js coffeescript backbone.js

0
推荐指数
1
解决办法
811
查看次数

这怎么不是coffeescript的功能?

似乎相对直截了当:

_.each words, (val, key) -> $(".word_choice")[key].html val
Run Code Online (Sandbox Code Playgroud)

退货:

$(".word_choice")[key].html is not a function
[Break On This Error]   

return $(".word_choice")[key].html(val);
Run Code Online (Sandbox Code Playgroud)

无法弄清楚这一点.我正在使用这个参考:

http://autotelicum.github.com/Smooth-CoffeeScript/literate/underscore.html#each

jquery coffeescript

0
推荐指数
1
解决办法
185
查看次数

为什么一个类不是其父类的"instanceof"?

Coffeescript代码:

class Animal
  constructor: (@name) ->

  move: (meters) ->
    alert @name + " moved #{meters}m."

class Snake extends Animal
  move: ->
    alert "Slithering..."
    super 5

alert Snake instanceof Animal
Run Code Online (Sandbox Code Playgroud)

这是一个链接.

我真的认为这个结果是真的.我的理由是这个__extends方法在编译的JavaScript中:

__extends = function (child, parent) {
    for(var key in parent) {
        if(__hasProp.call(parent, key)) child[key] = parent[key];
    }function ctor() {
        this.constructor = child;
    }
    ctor.prototype = parent.prototype;
    child.prototype = new ctor();
    child.__super__ = parent.prototype;
    return child;
};
Run Code Online (Sandbox Code Playgroud)

child.prototype.prototype 是父母.

有人可以告诉我为什么吗?我知道以下是真的:

alert new Snake('a') instanceof Animal
Run Code Online (Sandbox Code Playgroud)

coffeescript

0
推荐指数
1
解决办法
168
查看次数

静态css没有在快递玉中显示

编辑为ilollar答案(同样的问题)我有app.coffee:

pp.configure ->
  publicDir = "#{__dirname}/public"

app.set "views", viewsDir
app.set "view engine", "jade"

app.use(stylus.middleware debug: true, src: viewsDir, dest: publicDir, compile: compileMethod)
app.use(express.static(publicDir))

compileMethod = (str, path) ->
  stylus(str)
    .set('filename', path)
    .set('compress', true)


app.get "/pag",(req,res) ->
  res.render "pag",
  title: "test",
Run Code Online (Sandbox Code Playgroud)

在/stylesheet/pag.jade中:

...
link(rel='stylesheet', href='pag/css/bootstrap.min.css')
...
Run Code Online (Sandbox Code Playgroud)

当我去"myserver:9090/pag"时,页面没有加载bootstrap.min.css.我收到以下错误:

source :(my folder of proyects)/views/pag/css/bootstrap.min.styl
dest : (my folder of proyects)/public/pag/css/bootstrap.min.css
read : (my folder of proyects)/views/pag/css/bootstrap.min.styl
Error: ENOENT, open '(my folder)/views/pag/css/bootstrap.min.styl'
Run Code Online (Sandbox Code Playgroud)

我哪里错了?我可能错过了什么......任何想法?

css node.js coffeescript express pug

0
推荐指数
1
解决办法
4364
查看次数

Backbone 0.9.2视图初始化未被调用

我是Backbone.js的新手.我在v0.9.2应用程序上使用CoffeScript.该应用程序工作"很好",但initialize()视图的方法没有被调用.事件也没有正确绑定.我试图找出原因并非如此.我正在使用其他(手动)方法将事件绑定到元素,但不应该是这种情况.

应用程序实例化为:

window.Site =
  Models: {}
  Collections: {}
  Views: {}
  Routers: {}
  init: -> 
    new Site.Routers.MyRouter()
    Backbone.history.start()

$(document).ready ->
  Site.init()
Run Code Online (Sandbox Code Playgroud)

路由器:

class Site.Routers.MyRouter extends Backbone.Router
    routes:
        '': 'index'

    initialize: ->
        # some code here (this IS being called)

    index: =>
        # this is also being called since I am trying mysite.com/
        view = new Site.Views.MyView()
        $('#someId').html(view.render().el)
Run Code Online (Sandbox Code Playgroud)

风景:

class Site.Views.MyView extends Backbone.View

    template: JST['views/index']

    events:
        'click .someElement': 'someMethod'

    inititalize: ->
        console.log "hello" # NOT CALLED
        _.bindAll @
        @

    render: …
Run Code Online (Sandbox Code Playgroud)

coffeescript backbone.js

0
推荐指数
1
解决办法
2373
查看次数

HTML对象与jQuery对象

我是CoffeeScript和JavaScript新手.

在这里工作是一个空白的Rails 3.2.8应用程序.
这是直接的布局代码:

<!DOCTYPE html>
<html>
    <head>
      <title>Editor</title>
      <%= stylesheet_link_tag    "application", :media => "all" %>
      <%= csrf_meta_tags %>
    </head>
    <body>
        <%= yield %>
      <%= javascript_include_tag "application" %>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

不可能更简单吧?现在查看表单:

<%= form_for(@note) do |f| %>
  <% if @note.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@note.errors.count, "error") %> prohibited this note from being saved:</h2>

      <ul>
      <% @note.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.text_area :body, class: 'tkh-editable' %>
  </div>
  <div class="actions"> …
Run Code Online (Sandbox Code Playgroud)

javascript jquery ruby-on-rails coffeescript

0
推荐指数
1
解决办法
123
查看次数

JQuery - SyntaxError:保留字"this"无法分配

我正在尝试在JQuery中循环变量并重新分配this以下Coffeescript中的值.

$.each data.rows, ->
  completion_time = [this[0], new Date(new Date('Jan 01 2000').getTime() +  this[1])]
  this = completion_time
Run Code Online (Sandbox Code Playgroud)

但是,这会产生以下错误消息:

SyntaxError:无法分配保留字"this"

在每次迭代中,值this看起来像这样:

["abc123",12302103,1230132,1230123]

我要做的是将其重新分配给以下值:

["abc123",12302103]

我也尝试过分配this.value,没有骰子.有什么建议?

javascript jquery coffeescript

0
推荐指数
1
解决办法
444
查看次数

如何使用coffeescript在Express中创建app全局

我正在尝试在CoffeeScript中构建一个Express项目.我试图使app变量全局化,以便我可以在任何地方使用 - 从中​​读取配置设置.

到目前为止,我试过这个 -

在我的app.coffee文件中 -

app = express()
app.configure ->
    app.set 'host', 'localhost'
http.createServer(app).listen 8888, ->
    console.log 'Server started'
exports.app = app
Run Code Online (Sandbox Code Playgroud)

我想host在我的一个路由文件中访问上面的变量集.所以,我尝试了我的路由处理程序,

exports.app.get('host') # I get this undefined
Run Code Online (Sandbox Code Playgroud)

怎么做到这一点?我必须require(app)在我的路线文件中.app.coffee要求路由存在的模块,显然是路由,即

app.get '/', 'route_handler'
Run Code Online (Sandbox Code Playgroud)

node.js coffeescript express

0
推荐指数
1
解决办法
723
查看次数

在课堂上使用nextTick

如果我有这样的代码:

class SomeClass
  constructor: ->
    @someAttr = false

  someFunction: ->
    process.nextTick ->
      @someAttr = true

obj = new SomeClass
obj.someFunction()
obj.someAttr # Would still be false, because the @ (this) is in the process context
Run Code Online (Sandbox Code Playgroud)

它不起作用,因为process.nextTick将我们带入了一个不同的上下文,其中没有定义@someAttr.我该如何解决这个问题(当我想调用SomeClass的方法时)?

oop node.js coffeescript

0
推荐指数
1
解决办法
182
查看次数