How to delete multiple records using scripting

A small snippet of code to delete multiple selected records by user:

function deleteSelectedRows(){
try{
var bExist = "";
bExist = this.BusComp().FirstSelected();
while(bExist){
this.InvokeMethod("DeleteRecord");
bExist = this.BusComp().NextSelected();
}
this.BusComp().WriteRecord();
return (CancelOperation);
}
catch(e){
throw e;
}
finally{}
}