Observer Pattern
P173
Listing 7-6. The observer pattern
// If an event by the supplied name has not already been subscribed to, create an // array property named after the event name within the events object to store // functions to be called at a later time when the event by that name is triggered //如果所提供的名称(第一个参数)对应的事件还没有被订阅,则在events对象中添加一个属性,该属性的数据类型为数组,该属性的名称为该事件的名称,以此属性来保存在稍后该名称的事件被触发时所要调用的函数。 if (!events.hasOwnProperty(eventName)) { events[eventName] = []; }
---------------------------------------------------------------end