简体   繁体   English

了解javascript闭包

[英]Understanding javascript closure

function makeHelpCallback(help) {
  return function() {
    showHelp(help);
  };

//array elements here

  for (var i = 0; i < helpText.length; i++) {
    var item = helpText[i];
    document.getElementById(item.id).onfocus = makeHelpCallback(item.help);
}

I am having trouble understanding the last line. 我在理解最后一行时遇到了麻烦。 I have never seen the equal sign used in that way, 我从未见过以这种方式使用等号,

I have never seen the equal sign used in that way 我从未见过以这种方式使用等号

It assigns the return value of a function call (another function in this case; they are first class objects so can be passed around) to a property of an object. 它将函数调用的返回值(在这种情况下为另一个函数;它们是一流的对象,因此可以传递)分配给对象的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM