Last active
July 24, 2021 06:23
-
-
Save squaremo/5086573 to your computer and use it in GitHub Desktop.
Snippets for PMD post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Bloop() { } | |
var bloop = new Bloop(); | |
bloop.constructor === Bloop; // and indeed, | |
bloop.constructor === Bloop.prototype.constructor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Bleep() {} | |
Bleep.prototype = new Bloop(); | |
var bleep = new Bleep(); | |
bleep.constructor !== Bleep; // Eeeee! | |
bleep.constructor === Bloop; // Aaaaa! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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