Iterators and generators - MDC Doc Center

While custom iterators are a useful tool, their creation requires careful programming due to the need to explicitly maintain their internal state. Generators provide a powerful alternative: they allow you to define an iterative algorithm by writing a single function which can maintain its own state.

A generator is a special type of function that works as a factory for iterators. A function becomes a generator if it contains one or more yield expressions.

Javascript 的作法:
我們提供 Iterator 物件,也讓你用 prototype 來定義 custom iterator

如果你不想自己寫,我們也提供 iterator 的 factory,generator,
此時的作法就要用關鍵字 yield

Reflection (computer science) - Wikipedia, the free encyclopedia

ECMAScript

Here is an equivalent example in ECMAScript, and therefore works in JavaScript and ActionScript:

// Without reflection
new Foo().hello()
 
// With reflection
 
// assuming that Foo resides in this
new this['Foo']()['hello']()
 
// or without assumption
new (eval('Foo'))()['hello']()

[edit]