Skip to content

Instantly share code, notes, and snippets.

@squaremo
Last active July 24, 2021 06:23
Show Gist options
  • Save squaremo/5086573 to your computer and use it in GitHub Desktop.
Save squaremo/5086573 to your computer and use it in GitHub Desktop.
Snippets for PMD post
function Bloop() { }
var bloop = new Bloop();
bloop.constructor === Bloop; // and indeed,
bloop.constructor === Bloop.prototype.constructor;
function Bleep() {}
Bleep.prototype = new Bloop();
var bleep = new Bleep();
bleep.constructor !== Bleep; // Eeeee!
bleep.constructor === Bloop; // Aaaaa!
function lookup(args) {
var ranks = {};
var mostspecificmethod = false;
var mostspecificrank = [];
for (var i=0, len = args.length; i < len; i++) {
var position = 0;
var rolename = selector + ':' + i;
var newranks = {};
var arg = args[i];
do {
var methods;
var table = get_table(arg, false);
if (table !== undefined &&
(methods = table[rolename])) {
methods.forEach(function (methodname) {
// If this method hasn't qualified for
// previous arguments, it can't be
// applicable.
if (i > 0 && !(methodname in ranks)) {
return; // i.e., continue
}
var rank = (i > 0) ? ranks[methodname] : [];
newranks[methodname] = rank;
rank[i] = position;
if (i === len - 1 &&
(!mostspecificmethod ||
rank < newranks[mostspecificmethod])) {
mostspecificmethod = methodname;
}
});
}
arg = delegate(arg);
position++;
} while (arg !== null);
ranks = newranks;
}
return METHODS[mostspecificmethod];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment