欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

什么叫 inline function 内联函数

shiping1 的头像
内联函数是代码被插入到调用者代码处的函数。
像下面的 function 括在里面的 就是内联函数
var something = 10;

var something_else = 15;

var dynamic_value = (function(something,something_else){
  if(something == something_else){
    return "x";
  }else{
    return "y";
  }
})();








var base_value = 10;

var something_else = 15;

var dynamic_value = (function(base_value){
    return function (compare) {
        if(base_value == compare){
            return "x";
        } else {
            return "y";
        }
    };
})(base_value);

alert(dynamic_value(something_else));   // "y"
alert(dynamic_value(10));   // "x"

 

 

(function outerFunction() {
    var A = 'some variable';

   setTimeout(function(){ alert('I have access to A whether I use it or not'); }, 5);
})();

 

 

(function outerFunction() {
    var A = 'some variable';

    function myFunction() { alert('I have also have access to A'); };
    doStuff(myFunction);
})();



(function(){
  setTimeout(function(){ alert(111);}, 5);
})();


普通分类: