How can I avoid the self
variable here?
function urlBuilder(endpoint){
var status = ["user_timeline", "home_timeline", "retweets_of_me", "show", "retweets",
"update", "update_with_media", "retweet", "unretweet", "retweeters", "lookup"
],
friendships = ["incoming", "outgoing", "create", "destroy", "update", "show"];
let endpoints = {
status: status,
friendships: friendships
}
var self = { };
endpoints[endpoint].forEach(e => {
self[e] = endpoint + "/" + e;
});
return self;
}
somewhat better, still an assignment statement.
return [{}].map(el => {
endpoints[endpoint].forEach(e => {
el[e] = endpoint + "/" + e;
});
return el;
})[0];
.map
. Also,self
is a conventional name for context variable. This will reduce the readability instead. – Rajesh Aug 24 at 7:46