Last active
February 22, 2016 00:22
-
-
Save jdanyow/84be82e5430c6036a602 to your computer and use it in GitHub Desktop.
ModifySetObserver - grab refs to Set modifier methods
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
<!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> |
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
'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'); | |
} |
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
/* todo: add styles */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment