2012-09-10 36 views

回答

1

从来没有使用过这个,但是在一次点击中发现了这个。

searching keys is annoying and tedious. gawd! but wait... 

// test for existence of a key 
lawnchair(function(){ 
    this.exists('my-key-name', function(exists) { 
    console.log(exists) 
    }) 
}) 

什么打印到您的控制台?删除字符串应该有助于调试问题。

编辑 - 经过深入研究,exists函数有两个定义。

exists: function (key, cb) { 
    this.lambda(cb).call(this, !!(store[key])) 
    return this 
} 

而且

exists: function (key, cb) { 
    var exists = this.indexer.find(this.name+'.'+key) === false ? false : true ; 
    this.lambda(cb).call(this, exists); 
    return this; 
} 

他们都应该返回布尔值。第一个可能有点可疑。不确定。尝试在Lawnchair函数中包含带有注释和断点的扩展JS版本。你会很快找到发生的事情。

睡觉时间:)祝你好运。

+0

哈!相同的答案,同一时间。 “阅读文档!” :) –

+0

它显示“存在是:”[对象对象]。看着对象内部,没有布尔值。 – AndreiBogdan

+0

@AndreiBogdan - 这是存在的东西吗?你确定它返回任何东西,如果没有找到? – Aesthete

1

从来没有使用过,但the documentation suggests你的回调函数来exists会收到一个boolean参数:

// test for existence of a key 
lawnchair(function(){ 
    this.exists('my-key-name', function(exists) { 
     console.log('existence is: ' + exists) 
    }) 
})