Alice52 / vue-tutorial

this repo is about learning note about front
MIT License
0 stars 0 forks source link

[js] closure #1

Open Alice52 opened 4 years ago

Alice52 commented 4 years ago
var num = 15;
var fn1 = function(x) {
    // num is the value set when create this function
    // rather than setted when called scope
    // so num is 15
    if(x > num) {
        console.log(x);
    }
}

void function(fn2) {
    var num = 100;
    fn2(30)
}(fn1)

reference

  1. https://blog.csdn.net/dovlie/article/details/76339244