This piece of code is from Addy Osmani's online book, "Learning JavaScript Design Patterns".
// Extend an object with an extension
function extend( extension, obj ){
for ( var key in extension ){
obj[key] = extension[key];
}
}
It claims it can extend an object with an extension. It work well in the sample on the book. The controlCheckbox can function well for both definitions, Subject and DOM checkbox.
<input id="mainCheckbox" type="checkbox"/>
...
var controlCheckbox = document.getElementById( "mainCheckbox" ),
...
extend( new Subject(), controlCheckbox );
...
controlCheckbox["onclick"] = new Function( "controlCheckbox.Notify(controlCheckbox.checked)" );
But I just can't get the point why it is extended? The function definition of extend looks like overrding, instead of extending, controlCheckbox from an DOM checkbox to Subject, in my poor eyes. Can someone help me understand?