Skip to content

Commit

Permalink
protoMethods util
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Aug 21, 2020
1 parent d137d38 commit 9897414
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions protoMethods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable no-console */

'use strict';

console.log('WeakMap');
logProtoMethods(WeakMap);

console.log('WeakSet');
logProtoMethods(WeakSet);

function logProtoMethods(ctor) {
const proto = ctor.prototype;
const keys = Object.getOwnPropertyNames(proto)
.filter(key => key !== 'constructor')
.concat(Object.getOwnPropertySymbols(proto));
console.log('keys:', keys);
for (const key of keys) {
console.log('----------');
console.log(`${typeof key === 'symbol' ? `Symbol(${key.description})` : key}:`);
const method = proto[key];
console.log(typeof method === 'function' ? method.toString() : JSON.stringify(method));
console.log(Object.getOwnPropertyDescriptor(proto, key));
if (typeof method === 'function') console.log(Object.getOwnPropertyDescriptors(method));
}
}

0 comments on commit 9897414

Please sign in to comment.