Topic on Talk:ResourceLoader/Core modules

124.181.108.69 (talkcontribs)

Can anyone explain why this is a constructor? As far as I understand, it's just a convenient wrapper for $.ajax, which isn't a constructor.

Also, what is the correct way to use this when there's multiple requests? Do I have to make a variable for each request (lest jshint whine at me for using new for "side effects"), or can I just use the one? Eg:

var api = new mw.Api();
api.get('foo');
api.get('bar');

(which seems to work fine, by the way)

Mattflaschen (talkcontribs)

The class is a wrapper around $.ajax. However, one of the pieces of functionality it adds is being able to store options that apply to all requests using the object (unless overridden by the individual request). See https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Api . Your example above is not using new for side effects. In fact, the constructor really doesn't have side effects. It creates a mw.Api object, but to use that object for a network request, you need to call further methods (which the example above does).

This post was posted by Mattflaschen, but signed as Superm401.

124.181.106.190 (talkcontribs)

Alright, that seems useful in some cases. Thanks.

Reply to "mw.Api"