関数を持つオブジェクトがあります。このように使用すると、常に が返されますundefined
。this.client[method].read(params).done
関数が返すものを返すようにするにはどうすればよいですか?
rest.get('search', {query: 'Eminem', section: 'tracks'})
オブジェクトは次のとおりです。
var rest = {
// configuration
base: 'http://localhost/2.0/',
client: null,
get: function (method, params) {
// if client is null, create new rest client and attach to global
if (!this.client) {
this.client = new $.RestClient(this.base, {
cache: 5 //This will cache requests for 5 seconds
});
}
// add new rest method
if (!this.client[method]) {
this.client.add(method);
}
// make request
this.client[method].read(params).done(function(response) {
//'client.foo.read' cached result has expired
//data is once again retrieved from the server
return response;
});
}
}