I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
function Wiki(lang){
this.lang = lang || "fr";
this.inuse = false;
}
Wiki.prototype.research = function(s, callback){
if(this.inuse){
console.error("Wiki est déjà en cours d'utilisation !");
} else {
this.inuse = true;
let r = new XMLHttpRequest();
r.onload = function(){
Wiki.prototype.inuse = false;
let j = JSON.parse(r.responseText);
callback(j);
}
r.open('GET', "https://" + this.lang +".wikipedia.org/w/api.php?%20action=opensearch&format=json&origin=*&profile=normal&search="+encodeURIComponent(s));
r.send();
}
}
//EXEMPLE
var c = new Wiki();
c.research("Victor Hugo", function(result){
console.log(result);
});