I have the following function:
function messageService($http) {
return {
get: function (query) {
return $http.get("/api/v1/messages", { params: query });
},
delete: function (id) {
return $http.delete("/api/v1/messages/" + id);
}
}
}
But delete is a javascript reserved function and when I call this function I get an error. Is there a way to avoid this without changing the delete name?
You could use a string.
return {
...
'delete': function(id) {
return $http['delete']("/api/v1/messages/" + id);
}
};
Note that you only need to make it a string in ES3 or lower. As of ES5, keywords can be used as property names.
For more information on using reserved words for properties, see the MDN section covering it.
Reserved words actually only apply to Identifiers (vs. IdentifierNames) . As described in es5.github.com/#A.1, these are all IdentifierNames which do not exclude ReservedWords.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With