Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Last active February 22, 2016 00:22
Show Gist options
  • Save jdanyow/84be82e5430c6036a602 to your computer and use it in GitHub Desktop.
Save jdanyow/84be82e5430c6036a602 to your computer and use it in GitHub Desktop.
ModifySetObserver - grab refs to Set modifier methods
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
Look at <code>script.js</code>...
<script src="script.js"></script>
</body>
</html>
'use strict';
function createNumericSet() {
let s = new Set();
s.add = function(v) {
if (typeof v === 'number') {
Set.prototype.add.call(this, v);
}
return this;
}
return s;
}
/********************************
*
* Determine whether to use Set proto (current logic) or
* use new logic from @gingerik's PR....
*
* ******************************/
let s = createNumericSet();
//let s = new Set();
if (s.add === Set.prototype.add
&& s.delete === Set.prototype.delete
&& s.clear === Set.prototype.clear) {
console.log('use Set prototype');
} else {
console.log('grab refs to the add/remove/etc methods');
}
/* todo: add styles */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment