I have a javascript question relating to callback and timeout.
This is an example code snippet I wrote:
var f1 = function(){
    var result;
    window.setTimeout(
        function(){
            console.log("timeout in 100ms");
            result = 10;
        }.bind(this), 100);
    return result;
};
So, I want the function to modify the variable result. I used .bind(this) to ensure that it knows what result it.
still, the out put when I run f1() is 9, not 10, which is what I have desired.
Any clues?
 
     
     
    