Skip to main content
Tweeted twitter.com/#!/StackProgrammer/status/474442067909672960
Edited the code/question to differentiate the two options more clearly
Source Link

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 havewanted to grab a method named GetDependencies()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 GetDependenciesRegisterDependencies(register){
    register.add("Dep1", 1.1);
    register.add("Dep2", 1.2);
    register.add("Dep3", 1.3);
}

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 have a method named GetDependencies(), when would you do this:

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

And when would you do this?

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

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);
}
Source Link

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

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 have a method named GetDependencies(), when would you do this:

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

And when would you do this?

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