CoffeeScript is a little language that compiles into JavaScript. Underneath all of those embarrassing braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

learn more… | top users | synonyms

11
votes
3answers
4k 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 ...
10
votes
1answer
193 views

Tabbed navigation to hide and show pages

I'm new to jQuery and trying to learn how to refactor my bloated code to make it nicer and better maintainable. I have a tabbed navigation which I'm using jQuery to hide and show pages depending on ...
8
votes
1answer
204 views

Simple CoffeeScript navigation menu

I'm using simple script to handle tab menu like this: HTML: ...
7
votes
5answers
349 views

Avoiding nested conditionals and comparing strings

I have a web page with a set of icons that are grey by default: If a user clicks one, it toggles green (.toggleClass('green')): If a user clicks a green one, ...
6
votes
2answers
116 views

Optimize CoffeeScript comparison function

I've wrote this CoffeScript function to compare values in a table, but it turned out to be a HUGE function. Since the code is really really long, you can find it here as well. Code explanation: The ...
6
votes
1answer
133 views
6
votes
0answers
87 views

English-Russian irregular words tester

Could you please offer some suggestions about my self learning project? It is really hard-coded, but I have no idea what to do next. I'm using angular (only few ...
5
votes
2answers
213 views

isRTL.coffee - A JavaScript Library to determine if a text is of Right To Left direction

I just wrote this tiny library called isRTL.coffee to determine the direction of the text. Is there any better way of doing this? original code: ...
5
votes
2answers
51 views

Mathematical boundaries (audio meter)

I've just been putting together an audio meter by stacking bootstrap progress bars, and thought there was probably a better way, mathematically / logically, of achieving this. ...
5
votes
2answers
122 views

Periodic Table generator

I've been playing around with Jekyll and CoffeeScript the last few days and made a Periodic Table to learn those two. Now, to create the Periodic Table, I take an array of ...
4
votes
2answers
161 views

Get <TH> texts into a tab separated string

table_with_headers = $(this.dom.table).find("thead tr th").map(-> $(this).text() ).get().join("\t") Can one write it nicer? I especially dont like the inner ...
4
votes
2answers
2k views

Altering input field width

This gets every form element and calculates its width, then changes the input fields depending on the parent-form width: ...
4
votes
3answers
804 views

Converting a string to coordinates

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: ...
4
votes
1answer
201 views

Searching an object tree structure

I have this recursive function that searches an object tree structure: ...
4
votes
1answer
93 views

Flood game implementation

There is the implementation of flood game on my GitHub. The app.coffee is the main part of project: ...
4
votes
1answer
121 views

Resize renderer on browser window size change

For a game, there is some WebGLRenderer object that wraps around canvas element. There is need to update it's size when browser window size changes. Here goes my current code written using BaconJS. ...
4
votes
2answers
70 views

Initializing events on class

I wrote a simple class that substitutes all file inputs in an HTML for a more complex template and set some actions on it. The code is rather small, but I'm not used to write JavaScript. I wonder if ...
4
votes
1answer
676 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 ...
4
votes
3answers
144 views

Adding push to array inside the class that is being pushed

I used to mostly do this: ...
4
votes
1answer
162 views

Ruby on Rails text editor

I'm currently building a text editor using contenteditable and RoR back end. As the editor is WYSIWYG and trying to follow DRY, I used only one file to 3 actions: Show, Edit and New. Edit and new ...
4
votes
1answer
51 views

Refactor array for loop result

...
4
votes
2answers
5k views
4
votes
1answer
394 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. ...
4
votes
0answers
3k views

An Object-Oriented Programming pattern for AngularJS models using CoffeeScript classes

Over the past week, we tried to make our AngularJS model layer more powerful and reduce complexity in our controllers and template by using the object-oriented programming pattern and the CoffeeScript ...
3
votes
3answers
156 views

Can this coffeescripts method be simplified?

I'm new to coffeescripts. Can the getSum method be simplified more? Thanks ...
3
votes
1answer
101 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. ...
3
votes
2answers
387 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 : ...
3
votes
1answer
230 views

Functional Sundaram's sieve

I wrote this Sundaram's sieve in Coffeescript to quickly generate prime numbers up to limit: ...
3
votes
1answer
62 views

HTML5 Video player

I do HTML5 Video player with some controls. I have a button, where I change classname for make play, pause or replay button. I have a mute/unmute button, volume range slider, timer and fullscreen mode ...
3
votes
1answer
70 views

Regex for curly quotes and apostrophes

After years of fear and procrastination I decided to learn regular expressions. This is the result: CoffeScript: ...
3
votes
2answers
79 views

How can I remove DRY violations from this event handling code?

I've got a bunch of event handlers that follow this pattern: ...
3
votes
2answers
227 views

Fibonacci using cache

This is my simple Fibonacci implementation in CoffeeScript. What do you think? Using cache (fibResults), it's very very fast. ...
3
votes
1answer
67 views

Automatically gravitate popover towards page center

I've authored a couple of plugins which show popovers on a given element. One of the objectives for both was no specification of plugin direction. So instead of the implementing dev having to specify ...
3
votes
1answer
41 views

Set up event on class and initialize state [closed]

Very similar to this question, I'm curious about common patterns/best practices for handling events in coffeescript classes, particularly when you also need to call the event handlers immediately to ...
3
votes
1answer
107 views

How to refactor this series of JavaScript promises?

This is part of a class for paginating a Backbone collection. The paginateTo method is for paginating to a model id. It returns the model if it's already in the ...
3
votes
0answers
94 views

Create component with select+button

I'm new to ReactJs and trying to figure out the preferred style. I also have tried it enough to realize that I'm not a fan of jsx and prefer how React looks when written in coffeescript. This is a ...
2
votes
3answers
2k views

Function Is target String found in an Array of Strings in CoffeeScript

I wrote this simple function in CoffeeScript to see if elements are found in an array. ...
2
votes
2answers
1k views
2
votes
1answer
121 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? ...
2
votes
1answer
42 views

Cleaner Way to Test for Types? [closed]

I defined a function that multiplies its argument by 3: coffee> foo = (x) -> x * 3 [Function] We can call it with an input of 1: ...
2
votes
1answer
682 views

Coffeescript Operators: use &&, ||, etc., or keyword operators?

I often use js2coffee.heroku.com to help me convert JS to CoffeeScript. Here was a line of JS I was converting. ...
2
votes
1answer
107 views

NodeJS conditional request before the real request

In my code I have to login a user with username and password. But if the user sends his e-mail instead of his username, I have to resolve it with another request. This is what the code looks like: ...
2
votes
2answers
316 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 ...
2
votes
1answer
285 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
1answer
621 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 - ...
2
votes
2answers
108 views

Similar but slightly different JavaScript functions

I have two very similar functions that exist mainly for syntactic sugar. ...
2
votes
1answer
690 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 ...
2
votes
1answer
58 views

Wait for all resources to be loaded

In my application I need some resources to be loaded and I have services to load each of them and then I need some point to know that all requests finished. First thought was to use $q.all with array ...
2
votes
1answer
100 views

Backbone subviews with non-uniform layout

I have a “featured projects” view that requires its subviews conform to a non-uniform grid: one narrow column with 3 items, then one wide column with 2 items, followed by another narrow column with 3 ...
2
votes
0answers
17 views

Correcting a quiz

I wrote this code that's supposed to correct quizzes on a webpage, but it feels bloated and I'm sure there's tons of ways to improve it. Any thoughts? ...