我在网上找到了有问题的文件,事实证明这是有充分理由的。
首先,应该注意问题中的代码来自已缩进的缩小源。
这是一段代码:
var c=function(){},c={autoSelectFirst:!1,appendTo:"body",serviceUrl:null,lookup:null,
onSelect:null,width:"auto",minChars:1,maxHeight:300,deferRequestBy:0,params:{},
formatResult:g.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:!1,
onSearchStart:c,onSearchComplete:c,onSearchError:c,
// -----------^------------------^---------------^
所以这是问题中的代码,但还有更多。需要注意的重要一点是,该变量c
用于创建对象字面量,带有onSearchStart:c,onSearchComplete:c,onSearchError:c,
.
c
那么在对象中分配了哪个值?因为对象仍在创建过程中,这意味着c
仍在引用该函数,所以像onSearchStart
似乎是事件处理程序的属性将空函数作为默认值。
这更有意义。
为了验证,我还找到了原始的、未缩小的来源。以下是相关代码:
// v---originally it's called `noop`
var noop = function () { },
that = this,
defaults = {
autoSelectFirst: false,
appendTo: 'body',
serviceUrl: null,
lookup: null,
onSelect: null,
width: 'auto',
minChars: 1,
maxHeight: 300,
deferRequestBy: 0,
params: {},
formatResult: YithAutocomplete.formatResult,
delimiter: null,
zIndex: 9999,
type: 'GET',
noCache: false,
onSearchStart: noop, // <---here it's being used
onSearchComplete: noop, // <---here it's being used
onSearchError: noop, // <---here it's being used
所以现在更清楚的是noop
,通常代表无操作的 有自己的名称,并且确实在其下方创建的对象中使用。此外,这是整个文件中唯一使用的地方。noop
显然,缩小器足够聪明,可以看到最初调用的变量noop
将不再被使用,因此可以自由地为对象重用该变量名。令人印象深刻的代码分析,IMO。