Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to write a dot property in CoffeeScript without parentheses?

Tags:

coffeescript

Server = require('mongodb').Server

That's my CoffeeScript now. Any way to drop those ()?

like image 985
Shamoon Avatar asked Sep 20 '11 22:09

Shamoon


People also ask

How do you call a function without parentheses?

When we call a function with parentheses, the function gets execute and returns the result to the callable. In another case, when we call a function without parentheses, a function reference is sent to the callable rather than executing the function itself.

When can you only use dot notation and not bracket?

Dot notation is faster to write and easier to read than bracket notation. However, you can use variables with bracket notation, but not with dot notation. This is especially useful for situations when you want to access a property but don't know the name of the property ahead of time.

How do you use dot notation?

Dot notation is one way to access a property of an object. To use dot notation, write the name of the object, followed by a dot (.), followed by the name of the property. Example: var cat = { name: 'Moo', age: 5, }; console.

When should you use bracket notation instead of dot notation when accessing properties methods?

We must use bracket notation whenever we are accessing an object's property using a variable or when the property's key is a number or includes a symbol or is two words with a space.


1 Answers

This looks like a job for destructuring assignment!

{Server} = require 'mongodb'
like image 193
Trevor Burnham Avatar answered Oct 12 '22 23:10

Trevor Burnham