1

I would like to know what is difference in writing in below 2 ways :

Approach 1:

var onCallback = function(result) { 
    alert('way1');
};

function1(onCallback);

Approach 2:

function2(function(result) {
    alert('way2');
});
Nithesh Narayanan
  • 10,227
  • 32
  • 91
  • 134
androidraj
  • 75
  • 1
  • 7
  • Readability, usability, maintainability, re-usability of the function. Else it does the same thing. – dievardump Jul 22 '13 at 12:19
  • approach #1 in principal allows for accessing `onCallback` from another container embedding the js (like html `frame`, `iframe`elements or `svg`roots). – collapsar Jul 22 '13 at 12:23

1 Answers1

1

Approach 1 could be reused. (which might do some problems, because the code can be altered, but shouldn't)

Approach 2 has no refference

that's the only difference

Philipp Sander
  • 9,615
  • 3
  • 41
  • 75
  • 1
    `onCallback` is also anonymous; it's just that it's also referenced by a variable. – Jon Jul 22 '13 at 12:20
  • 1
    in approach 1, some other code portion might alter the definition of 'onCallback'. feels like a maintenance disaster to happen. – collapsar Jul 22 '13 at 12:21