我不确定如何描述我想要的内容。我想定义一个函数,其参数是一个本地VALUE而不是一个参考。创建具有值参数的函数引用not references
说,我有我想创建
for(i = 0; i < 10; i++){
var div = document.createElement("div");
div.onclick = function(){alert(i);};
document.appendChild(div);
}
现在我相信在这个例子中,无论我点击了什么格,它会提醒“10”的对象列表;因为这是变量i的最后一个值;
有没有办法/我如何创建一个函数,参数是我在指定函数时的值...如果这是有道理的。
在函数内部,'i'是一个捕获的变量,而不是一个参数。 – SLaks 2010-03-16 00:11:18
参见: http://stackoverflow.com/questions/1734749/ http://stackoverflow.com/questions/643542/ http://stackoverflow.com/questions/1582634/ HTTP:/ /stackoverflow.com/questions/1331769/ http://stackoverflow.com/questions/1552941/ http://stackoverflow.com/questions/750486/ http://stackoverflow.com/questions/933343/ http://stackoverflow.com/questions/1579978/ http://stackoverflow.com/questions/1413916/ ...以及更多... :) – CMS 2010-03-16 00:27:54
@CMS:是的;我已经获得了很多回应这种问题的声誉。 – SLaks 2010-03-16 00:28:57