Trying to learn to create a standalone game.js
plugin.
What is the best practice to call a function that depends on the result of two other separate functions? and sometimes call one function only.
for example:
- function A{}
- function B{}
- function C{}
How to achieve this logic: result= C( B( A() ) );
in other pages; only need to call C();
I read this answer, but it didn't match my requirements.
for example; some block of jquery:
userID = 123;
$(function () {
points = load_points(userID); // load points
refresh(points); // refresh points' span and animate
popup(points); // pop up user the points
function load_points(userID) {
// Read points from a PHP/MySQL page using Ajax then Return points
// sample output: 100 point
return result;
}
function refresh(p) {
// update span value then animate
$("#spanID").text(p);
$("#spanID").slideDown(1000);
return true; // return true after 1000 ms
}
function popup(msg) {
// if #spanID value updated and animated
// ; show overlay popup with points.
// using this popup plugin here
//http://dev.vast.com/jquery-popup-overlay/
alert("You win " + msg+ " Points");
}
});
The reason not wrapping everything in one function; is some functions are called several times.
For example:
Sometimes I want to refresh points in a page without showing the popup. Some other places I want to show the popup with different requirements.
I am concern about
The functions order.The success order related to functions' timing. i.e. I want to call a function after the result is available from the other function.- The speeds of the whole process.