Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Using an object of functions as a parameter into a function

function test({start, finish})
{

start();
finish();
}


function run()
{
	let obj = {start(){console.log("start");}, finish(){console.log('finish')}};
	test(obj);
}
/*test will console.log 'start' and 'finish'*/
/*Note in the above example the names of functions MUST MATCH. test({x, y}) would NOT have worked.*/
/*not recommended unless you know the names of the input functions ahead of time*/
 
PREVIOUS NEXT
Tagged: #Using #object #functions #parameter #function
ADD COMMENT
Topic
Name
1+6 =