Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mnemonic for remembering Coffeescript's `in` vs `of`

Tags:

coffeescript

I've been using Coffeescript all day every day for three months. I love it. There are a few little learning niggles with how it translates to JS, but I've gotten over all of them except one:

How do I remember whether to use in or of when iterating over loops and arrays? http://coffeescript.org/#loops

Sometimes I need the key and value, sometimes I only need the value. Both of and in work on both arrays and objects to iterate.

Can someone recommend a mnemonic for remembering which one is which?

This would be very valuable to me. I'm tired of going to the doc site for this same thing over and over again :)

Example from a different domain: I always remember that west is on the left and east is on the right of a compass because it spells "we".

like image 322
SimplGy Avatar asked Jul 26 '13 16:07

SimplGy


People also ask

What are mnemonics?

Mnemonics are memory tricks that can help you remember long strings of information, often in a particular order. You have been using mnemonic devices since...well, before you can remember! Mnemonic devices have helped people achieve phenomenal feats in the world of memory.

How do you use mnemonic devices to remember?

One type of mnemonic device is making the information you need to learn into a sort of song or poem. You can do this by setting the information to music. The ABC song is a great way to remember information because the tune is so memorable. Or, you can simply use rhymes.

Do spelling mnemonics really work?

It is a widely used effective strategy to learn spelling words faster. Spelling mnemonics are mainly used to learn irregularly spelled words or commonly misspelled words because they don’t follow traditional spelling rules or patterns, but they are not limited to that only.

What are some good mnemonics for typing?

Backslash leaning backwards is pretty much the usual mnemonic as far as I know. It helps if you remember you type from left to right, and then the cursor always moves right - facing right. Show activity on this post.


1 Answers

This sentence of the linked documentation seems particularly apt:

Comprehensions can also be used to iterate over the keys and values in an object. Use of to signal comprehension over the properties of an object instead of the values in an array.

Basically, think "items in an array", "properties of an object".

like image 88
nneonneo Avatar answered Nov 22 '22 06:11

nneonneo