Callbacks: when to return value, and when to modify parameter?

Posted by MarkN on Programmers See other posts from Programmers or by MarkN
Published on 2014-06-03T15:46:00Z Indexed on 2014/06/03 21:39 UTC
Read the original article Hit count: 248

When writing a callback, when is best to have the callback return a value, and when is it best to have the callback modify a parameter? Is there a difference?

For example, if we wanted to grab a list of dependencies, when would you do this:

function GetDependencies(){
    return [{"Dep1" : 1.1}, 
            {"Dept2": 1.2}, 
            {"Dep3" : 1.3}];
}

And when would you do this?

function RegisterDependencies(register){
    register.add("Dep1", 1.1);
    register.add("Dep2", 1.2);
    register.add("Dep3", 1.3);
}

© Programmers or respective owner

Related posts about design

Related posts about design-patterns