2014-10-27 55 views
0

我想檢查此選項中的緩存參數。參數檢查函數使用鏈接方法

所以如果param被包含並且是真的,那麼.use會設置no_cache - 其他的不會。

My.function = function (data, callback, cache) { 
return this.client.request("patch", this.uri()) 
    .use(no_cache) 
    .send(data) 
    .end(utils.easy(callback)); 
}; 

這樣做的最佳方法是什麼?

回答

0

如果沒有發送true,則不確定要發送的內容。也許未定義?您可以使用三元操作

My.function = function (data, callback, cache) { 
return this.client.request("patch", this.uri()) 
.use(cache === true ? no_cache : undefined) 
.send(data) 
.end(utils.easy(callback)); 
};