chunpin
7/25/2017 - 4:58 AM

runWithDebugger.js

function runWithDebugger(callback,optionalArray){
	   // check if there's callback function 
	   if(callback){
	   		// if there's optional arguments As array 
	   		if(optionalArray){
	   			// check if optionalArray is an array
	   			if(Array.isArray(optionalArray)){
	   				debugger;
	   				callback(optionalArray[0],optionalArray[1]);
	   			} else {
	   			// if optinalArray is not an array, throw typeError
	   				throw new TypeError('please pass an Array as optional argument');
	   			}
	   		}  else{
	   		// no optional Array	
	   			debugger;
	   			callback();
	   		}
	   } else{
	   // check if there's NO callback function 
	   	  throw new TypeError('forgot pass in a callback funciton ?');
	   }
}