@דוד ל.ט.
תלונתו היא שאתה ניגש לvalur בלי לבדוק קודם שהerror ריק (אם תוסיף if (!err) אזי הוא ישתוק כנראה), אבל נשגב מבינתי איך ה"חוזה" הזה מוכר לIDE.
עכשיו מצאתי איך הפונקציה עובדת
באמת עם try (מושג חדש שלא הכרתי עד שהכרת לי)
LevelUP.prototype.get = function (key_, options, callback) {
var self = this
, key
callback = getCallback(options, callback)
if (maybeError(this, options, callback))
return
if (key_ === null || key_ === undefined || 'function' !== typeof callback)
return readError(this
, 'get() requires key and callback arguments', callback)
options = util.getOptions(options)
key = this._codec.encodeKey(key_, options)
options.asBuffer = this._codec.valueAsBuffer(options)
this.db.get(key, options, function (err, value) {
if (err) {
if ((/notfound/i).test(err) || err.notFound) {
err = new NotFoundError(
'Key not found in database [' + key_ + ']', err)
} else {
err = new ReadError(err)
}
return dispatchError(self, err, callback)
}
if (callback) {
try {
value = self._codec.decodeValue(value, options)
} catch (e) {
return callback(new EncodingError(e))
}
callback(null, value)
}
})
}
פורסם במקור בפורום CODE613 ב06/09/2015 21:32 (+03:00)