Mathmagician Wiki
Advertisement

Compacting lengthy conditions[]

// lengthy
if (x === 'a' || x === 'b' || x === 'c' || x == 'd') {
    console.log(x);
}

// same thing but shorter with regex test
if (/^(a|b|c|d)$/.test(x)) {
    console.log(x);
}

Function arguments and apply[]

function x() {
    console.log("this =", this, "\narguments =", arguments);
}
x(1, 2, 3);
x.apply('this is this', [1, 2, 3]);

Query MediaWiki API[]

var url = wgServer + '/api.php?action=query&meta=siteinfo&siprop=statistics&format=json';
 
function cb (data) {
    console.log(data.query.statistics);
}

$.getJSON(url, cb);
Advertisement