coffeescript

Coffescript Callbacks & Functions

大憨熊 提交于 2019-12-11 21:32:17
问题 I have this function and I am trying to use two large functions made up of smaller ones and one while loops. One for when it's the players turn, one when it's the opponent's turn, and a while loop when the player has won. When I run it in the browser, the buttons do not do anything. What is wrong? $attackButtonClick = (opponent) -> if playersTurn and not player.Win player.attack(opponent) if opponent.currentHealth <= 0 player.Win = true; allOff() postBattle(opponent) else playersTurn = false;

Pass a list of named functions into function in coffeescript

断了今生、忘了曾经 提交于 2019-12-11 20:22:07
问题 In the API Documentation there is a snippet: casper.waitFor(function check() { return this.evaluate(function() { return document.querySelectorAll('ul.your-list li').length > 2; }); }, function then() { this.captureSelector('yoursitelist.png', 'ul.your-list'); }, function timeout() { this.echo("I can't haz my screenshot.").exit(); }); I need this, but in a coffeescript project. I tried to rewrite it into coffeescript but it didn’t work. Even if i let js2coffe do the job, i get some invalid

Weird behaviour with Ajax request

爷,独闯天下 提交于 2019-12-11 18:59:18
问题 I have a loop that is making multiple ajax gets. for dataType in @dataTypes url = someUrl + dataType console.log(dataType) console.log url $.ajax( url : url type : 'GET' success : (data) => @populateSearchIndices(data,dataType) ) populateSearchIndices:(data,dataType)-> console.log "looking at what indexes are there" console.log dataType indices = [] for object in data indices = indices.concat(Object.keys(object)) console.log "indices" console.log indices arr = @typeIndexMap[dataType] if arr

Why did I failed to connect to websocket?

最后都变了- 提交于 2019-12-11 18:07:43
问题 The code of Node server with ws module: show = console.log WS = require('ws').Server wss = new WS port: 8080 wss.on 'connection', (ws) -> show 'a connection' ws.on 'message', (message) -> show 'received: %s', message ws.send 'something' I can connect to websocket by running the code below on the same server, and it gives out "a connection" : WS = require 'ws' ws = new WS 'ws://localhost:8080' But when I run these lines of code from browser, there's no respose: s = new WebSocket('ws://184.82

How do I fetch a backbone.js model from serialized json from a mvc3 model?

孤街醉人 提交于 2019-12-11 17:48:53
问题 If I had a model like this in my MVC3 application: public class Person { public Guid Id { get; set; } public Name Name { get; set; } public Address Address { get; set; } public PhoneNumber PhoneNumber { get; set; } } public class Name { public string First { get; set; } public string Last { get; set; } } public class Address { public string AddressLine { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } } How would do I populate it

How to ensure the javascripts/channels/chatrooms.coffee is loading and receive: (data) works? Console.log data is not loading

倖福魔咒の 提交于 2019-12-11 17:38:42
问题 Here is the file, containing what should receive from the Message Relay Job that successfully loads on the server. App.chatrooms = App.cable.subscriptions.create "ChatroomsChannel", connected: -> # Called when the subscription is ready for use on the server disconnected: -> # Called when the subscription has been terminated by the server received: (data) -> console.log(data) active_chatroom = $("[data-behavior='messages'][data-chatroom-id='#{data.chatroom_id}']").append("<div><strong>#{data

coffeescript syntax {var}?

别来无恙 提交于 2019-12-11 16:34:46
问题 Very simply I am seeing the following syntax using coffeescript in node, that I never saw using coffeescript in the browser. {foo} = app.locals.foo I headed over to js2coffee to see what this does, but it appears to be identical in js output to foo = app.locals.foo So what is going on here? What does the {} syntax mean in this context? Why would you use it? 回答1: From the fine manual: Destructuring Assignment To make extracting values from complex arrays and objects more convenient,

Rails 3 Javascript Not Working

試著忘記壹切 提交于 2019-12-11 16:27:12
问题 I have included Javascript with <%= javascript_include_tag "application" %> in my Rails 3.2 application. And, I have included the following CoffeeScript in the company.js.coffee file that is included in the final application.js file when run: $("article h2 a").click (e) -> $("article div").hide() $(@hash).slideToggle() e.preventDefault() $("article div:not(#1)").hide() However, the script doesn't work at all, despite functioning in the original HTML file that it was copied from (albeit not in

coffeescript is always returning the response object

旧城冷巷雨未停 提交于 2019-12-11 15:43:52
问题 i've the following codes in coffeescript getSection = (url) -> req = $.getJSON url return req.success (data) -> data.section or, getSection = (url) -> req = $.getJSON url req.success (data) -> data.section i intended to return data.section for the function getSection . but it is always returning another object (probably the response/ajax object). how can I force to return the values in data.section from this inner function? thanks in advance? 回答1: $.getJSON is an AJAX call and A stands for

Emberjs Complex Routing

懵懂的女人 提交于 2019-12-11 14:57:16
问题 In my application there is a client side for members to select bottles and an admin section to manage members, bottles, lockers etc. that both use the same models so I figured that my my router should look like this: App.Router.map -> @.route "signin" #Restuarant signs in to the application @.resource "member", -> @.route "signin" #Members sign in to see their bottles @.resource "member", path: ":member_id", -> @.resource "bottles", -> @.route "select" @.resource "transcations", -> @.route