This:
{EventEmitter} = require 'events'
is equivalent to this JavaScript:
var EventEmitter;
EventEmitter = require('events').EventEmitter;
When you require 'events'
, you're getting an object back with the module's exports, one of those exports is the EventEmitter
"class". Using {EventEmitter}
is just an idiomatic shortcut for pulling EventEmitter
out of the object that require 'events'
returns; you could also say this:
EventEmitter = require('events').EventEmitter
if you prefer. The braced version starts to come in handy when you want to extract more than one part of an object; for example, this:
{a, b} = c
is like this JavaScript:
var a, b;
a = c.a;
b = c.b;
The Destructuring Assignment section of the CoffeeScript documentation might make some good reading right about now.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…