Created
February 16, 2015 06:17
-
-
Save pchw/3f168e7da85e2ea2d9c0 to your computer and use it in GitHub Desktop.
for-of vs _.map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = require('underscore') | |
class Bar | |
constructor: -> | |
@bar = "Bar!" | |
baz: 'Bar!' | |
class Foo extends Bar | |
constructor: -> | |
@foo = "Foo!" | |
obj = new Foo | |
console.log "=== for-of ===" | |
for k, v of obj | |
console.log "#{k}:#{v}" | |
console.log "=== _.map ===" | |
_.map obj, (v,k)-> | |
console.log "#{k}: #{v}" | |
console.log "=== object hash ===" | |
dict = | |
foo: 'foo' | |
bar: 'bar' | |
baz: 'baz' | |
for k, v of dict | |
console.log "#{k}:#{v}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ pbpaste | coffee -s | |
=== for-of === | |
foo:Foo! | |
constructor:function Foo() { | |
this.foo = "Foo!"; | |
} | |
baz:Bar! | |
=== _.map === | |
foo: Foo! | |
=== object hash === | |
foo:foo | |
bar:bar | |
baz:baz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment