Sunday 15 March 2015

javascript - Passing in a function to another function? -


Is there a better practice to use it to reduce the scope of a function in any other function? I am getting quite confused about this stuff.

without passing it;

  function loadSuccess (a, b, c) {}; Function image (url, name, info) {var asset = new Image (); Asset.addEventListener ("Load", Function (Name, Info) {Return Work () {loadSuccess (this, name, information);}} (name, info), Incorrect); Asset.src = url; }; Image (A, B, C);   

and pass it in;

  function loadSuccess (a, b, c) {}; Function image (url, name, info, loadsuit) {var asset = new Image (); Asset.addEventListener ("load", function (name, information, fanc) {return function () (function), (this, name, information);}} (name, information, loadsut), incorrect); Asset.src = url; }; Image (a, b, c, loadSuccess); Performance benefits are not negative, but going through a callback makes your work more flexible, if you get permission to pass a different callback in a different situation, if necessary.  

However, I see a problem in your code: TT does not make any sense to return anything from an asynchronous callback, it is not your image function, which it does not Returning the code,

Keeping in mind those problems, I will change the code as follows:

  function loadSuccess (a, b, c) {}; Function image (url, name, info, fancy) {var asset = new Image (); Asset.addEventListener ("Load", function (e) {func (this, name, info);}, false); Asset.src = url; }; Image (a, b, c, loadSuccess);   

I removed the function you immediately applied, because I do not see any good reason to use it.

No comments:

Post a Comment