Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coffeescript and jQuery chaining

I'm attempting this in coffeescript:

$( element ).mousedown( aFunction ).mouseup( anotherFunction );

I'm trying to work out a way to make use of indents so that something like the following will return what's about:

$ element
    .mousedown aFunction
    .mouseup anotherFunction

But to no avail, are there any recommendations for chaining in coffeescript?

like image 352
Ahmed Nuaman Avatar asked Jun 25 '12 18:06

Ahmed Nuaman


People also ask

Is CoffeeScript still a thing?

As of today, January 2020, CoffeeScript is completely dead on the market (though the GitHub repository is still kind of alive).

What is CoffeeScript used for?

CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python, and Haskell in an effort to enhance JavaScript's brevity and readability. Specific additional features include list comprehension and destructuring assignment.

Is CoffeeScript like JavaScript?

One crucial difference between the two languages is that TypeScript is the superset of JavaScript while CoffeeScript is a language which is an enhanced version of JavaScript. Not just these two languages but there are other languages such as Dart, Kotlin, etc. which can be compiled into JavaScript.


1 Answers

I'm sure you don't want to use parenthesis, but...

$("#element")
  .mousedown(aFunction)
  .mouseup(anotherFunction)

Compiles to

$("#element").mousedown(aFunction).mouseup(anotherFunction);
like image 62
Kyle Avatar answered Oct 05 '22 15:10

Kyle