3
How is it possible to use a function as an object? More precisely, I would like to repeat the behavior of $http
angular, where it is possible to execute a request in the following forms:
$http.get('url');
$http.post('url', data);
$http({
method: 'get',
url: 'url',
...
});
Note that the function $http
can be either invoked directly or used as an object to obtain the properties get
and post
.
I did tests by setting the properties within the function (using
this
,var
,return
) and there was no way, when the solution was easier than I imagined... This way it is also possible to use theprototype
right?– Oeslei
I can’t tell you exactly how it would be with
prototype
, but the way it works I believe it’s different, in his case I believe it would really be for objects created bynew
– Leandro Godoy Rosa