functionaddForm(formInstance){ if(!implements(formInstance, 'Composite', 'FormItem')){ thrownewError("Object does not implement a required interface"); } //...... }
//The implements function, which checks to see if an object delcares that it //implements the required interfaces.
functionimplements(object){ for(var i = 0; i < arguments.length; i++){ var interfaceName = arguments[i]; var interfaceFound = false; for(var j = 0; j < object.implementsInterface.length; j++){ if(object.implementsInterface[j] == interfaceName){ interfaceFound = true; break; } } if(!interfaceFound){ returnfalse; //An interface was not found. } } returntrue; //All interface were found. }