Coffeescript is an alternative syntax for Javascript.
1
vote
2answers
51 views
Cleanest way to close over a counter in CoffeeScript
I haven't spent too much time with CoffeeScript and am trying to have a simple counter:
casper.on('step.complete', ( ->
i = 0
return (step) ->
i += 1
...
1
vote
1answer
30 views
JQuery Dynamic Dropdown Update
This is based (somewhat loosely) on the code written in this railscast. I'm planning to re-use it in different places throughout the site, so I made it a bit more generic rather than based on IDs. ...
3
votes
2answers
35 views
Passing Context in CoffeeScript
I'm trying to migrate from JavaScript to CoffeeScript. However I'm not sure about the best way to optimize the code generated by js2coffee.
Below is the original JavaScript source :
var async = ...
0
votes
0answers
68 views
Angular JS photo app for personal cloud
I've been working on my first Angular JS app for the past few days.
It's in a very early stage (no real functionality), but that will only make it easier to review what IS there.
The client side is ...
3
votes
1answer
110 views
Functional Sundaram's sieve
I wrote this Sundaram's sieve in Coffeescript to quickly generate prime numbers up to limit:
sieve_sundaram = (limit) ->
numbers = (n for n in [3...limit+1] by 2)
half = limit / 2
...
2
votes
0answers
63 views
Code review CoffeeScript implementation of A* algorithm
a_star = # returns the goal node (or null if path not found). To reconstruct path follow the node.__src till null
(
start, # starting node
...
2
votes
2answers
128 views
My first real JS project, simple form validation
I would really like to hear how I can improve my form validator.
Next, I want to refactor it into OO and learn a testing framework like Jasmine.
Some things I know I could improve
Don't make it ...
3
votes
2answers
230 views
Better way to do this in coffeescript
I was actually writing this little script:
$ ->
# Alter 'input' Width
inputResize = ->
$('form').each ->
tF = $(this)
formWidth = tF.width()
tF.find('input').each ->
...
1
vote
1answer
178 views
Increasing web load time (coffee script and d3.js) [closed]
I took the Bubble chart visualization from Jim Vallandingham: http://vallandingham.me/vis/gates/ and added a few other features such as: a picture over svg, a click function, option to select only ...
3
votes
2answers
490 views
CoffeeScript date formatting
forceTwoDigits = (val) ->
if val < 10
return "0#{val}"
return val
formatDate = (date) ->
year = date.getFullYear()
month = forceTwoDigits(date.getMonth()+1)
day = ...
2
votes
1answer
91 views
Assign local-variables in constructor
How to make this code in constructor more DRY?
Is there some more concise way to assign variables passed through object?
class Ball
constructor: (args) ->
@name = args.name
@x = ...
3
votes
1answer
78 views
CoffeeScript method refactoring
This method is from Backbone-View. I'd like to refactor it but I don't have much experience with Coffee or JavaScript.
linkStyle: ->
if @model.get('published')
'published'
else
...
2
votes
0answers
139 views
Object Wrapper/Parameter Injection Module for CoffeeScript/JavaScript
I made an object wrapper/parameter injector and I hope it will be useful, I made it for a project I am working on but then decided to try polishing it a bit.
The use case is for wrapping objects such ...
2
votes
2answers
75 views
Is there any way to make this CoffeScript code simpler / smaller
I've just started with coffeescript, and I saw http://blog.8thlight.com/uncle-bob/2012/04/20/Why-Is-Estimating-So-Hard.html which has a little programming problem, so I figured I'd do it in ...
4
votes
3answers
121 views
Can this coffeescripts method be simplified?
I'm new to coffeescripts. Can the getSum method be simplified more? Thanks
MyObject =
checkCondition: (num) ->
return true if num is 5
getSum: (num) ->
total = 0
total += i for ...
2
votes
0answers
267 views
PageObject implementation (CoffeeScript, CasperJS)
I'm using CasperJS and CoffeeScript for integration testing of a hobby project. Page Objects seem to be a useful abstraction. I had two major requirements:
Support for node.js style callbacks - ...
0
votes
1answer
91 views
looking to make this code cleaner
I need to count non-transparent pixels in a canvas. My code is below. I am pretty sure there is a nice and elegant syntax for doing this. But I am new to coffeescript. Please help. Note that the data ...
5
votes
1answer
208 views
Project Euler question 2 in CoffeeScript
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
fib = (x) ->
return 0 if x == 0
return 1 if x == 1
...
4
votes
1answer
299 views
Where is the memory leak in this scraper?
This is a scraper written in coffee-script for nodeJS. It is run in an interval (set to 5 seconds here to dramtically show the leak). Somewhere this code leaks memory. I already tried nulling a few ...
3
votes
1answer
148 views
Is there a better way to structure this in CoffeeScript?
I have this recursive function that searches an object tree structure:
dataSearcher = (dataElement, identifierToFind) ->
if dataElement.identifier == identifierToFind
...
0
votes
1answer
99 views
Is there any javascript pitfalls with this approach that I might be missing?
I have a model with a number of complex/simple properties that has a corresponding strongly typed view, that calls EditorFor to a custom editor template view for the model.
One of the form's ...
2
votes
2answers
90 views
Similar but slightly different JavaScript functions
I have two very similar functions that exist mainly for syntactic sugar.
deactivate = (el, seek) -> el.find(seek).removeClass("active")
activate = (el, seek) -> el.find(seek).addClass("active")
...
0
votes
1answer
90 views
Writing binding providers in CoffeeScript?
In his KnockoutJs 1.3 beta post, Steve Sanderson has an example of using Binding providers ("5. Binding providers (and hence external bindings)") where he makes a comment in the JSFiddle JavaScript ...
4
votes
3answers
130 views
Adding push to array inside the class that is being pushed
I used to mostly do this:
class Person
constructor : (@parent, @data)->
@index = @parent.length
class People
constructor : ->
people = []
for data in database.people
...
2
votes
1answer
462 views
A library written in CoffeeScript
So, I wrote this small library for fast DOM building with API tailored for CoffeeScript
I feel like the code overall can be made better/smaller/faster.
I am also not particularly happy about a few ...
4
votes
4answers
577 views
Short coffeescript style question
I'm going through the CoffeeScript book by Trevor Burnham, and I was curious as to what the best style is for a function I was writing.
In the book the author writes the function like so:
...
9
votes
3answers
3k views
Coffeescript beautification and refactoring
As much as I try, I cannot seem to get this Coffeescript code to look beautiful (I'd like to think it is possible). I have tried both Javascript and Coffeescript. Just to be clear, this code works ...