0

I'm trying to convert jquery into coffeescript but I'm getting syntax error

SyntaxError: unexpected REGEX

This is my code:

container = document.querySelector('#style-container');
msnry = new Masonry( container, {
  // options
  columnWidth: 200
  itemSelector: '.item'
});

What am I doing wrong?

Thanks!

3 Answers 3

1

That's not CoffeeScript. This is CoffeeScript:

container = document.querySelector "#style-container" 
msnry = new Masonry(container,
  columnWidth: 200
  itemSelector: ".item"
)

You can convert JavaScript to CoffeeScript using this tool.

The specific error is referring to the comment tag. // doesn't mean a comment in CoffeeScript, so it falls back to an empty regular expression. A more useful regular expression would be /[0-9]+/, however the contents are optional in CoffeeScript.

// this is a JS comment
# this is a CS comment
Sign up to request clarification or add additional context in comments.

Comments

0

The error is you are using // for a comment instead of #.

In addition to that, you example still looks more like JavaScript than CoffeeScript, but that's the specific error you are getting. See also http://js2coffee.org/

Comments

0

CoffeeScript comments start with #, instead of //. As noted above the // is used for a blank regex. When learning CoffeeScript, I recommend http://coffeescript.org/ and the Try CoffeeScript tool, so that you can see the JavaScript that your CoffeeScript would give rise to.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.