Addy,
First, thank you for writing Learning Javascript Design Patterns, I reference it all the time, and would not understand javascript nearly as well without your publication!
Going through the Observer Pattern today, I noticed an omission in the RemoveAt function:
// Currently Printed Online:
ObserverList.prototype.RemoveAt = function( index ){
if( index === 0 ){
this.observerList.shift();
}else if( index === this.observerList.length -1 ){
this.observerList.pop();
}
};
// Correction
ObserverList.prototype.RemoveAt = function( index ){
if( index === 0 ){
this.observerList.shift();
}else if( index === this.observerList.length -1 ){
this.observerList.pop();
} else {
this.observerList.splice( index, 1 );
};
From the site:
Addy, First, thank you for writing Learning Javascript Design Patterns, I reference it all the time, and would not understand javascript nearly as well without your publication!
Going through the Observer Pattern today, I noticed an omission in the RemoveAt function:
// Currently Printed Online:
ObserverList.prototype.RemoveAt = function( index ){ if( index === 0 ){ this.observerList.shift(); }else if( index === this.observerList.length -1 ){ this.observerList.pop(); } };
// Correction
ObserverList.prototype.RemoveAt = function( index ){ if( index === 0 ){ this.observerList.shift(); }else if( index === this.observerList.length -1 ){ this.observerList.pop(); } else { this.observerList.splice( index, 1 ); };
Thank you again,
Tim