Created
August 17, 2016 09:40
-
-
Save davidsharp/223738af901324b81ae18a98b6399cdc to your computer and use it in GitHub Desktop.
(Super WIP) Build boolean is/isNot functions, both simple and complex, quickly and (reasonably) easily
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 snot(o,funcs,isNots=true){Object.keys(funcs).forEach((c)=>{o['is'+c]=funcs[c].bind(o)})} | |
/* | |
Desired usage (we're not quite there yet): | |
var myObj = {foo:true, value:1337} | |
snot(myObj,{ | |
foo:function(){return this.foo===true;}, | |
valueABigNumber:function(){return this.value>100;}, | |
valueBiggerThan:function(someNumber){return this.value>someNumber;} | |
}) | |
myObj.isFoo(); //true | |
myObj.isValueABigNumber(); //true | |
myObj.isValueBiggerThan(1338); //false | |
myObj.isNotFoo(); //false - one day, at least... | |
*/ | |
//TODO: Implement isNots | |
//TODO: camelCase all the things!!! | |
//TODO: Type checking for boolean (and boolean forcing) | |
//TODO: De-ES2016 | |
//TODO: Handle being passed arrow functions | |
//TODO: Test and document better examples | |
//TODO: Work out details for use on prototypes (I /guess/ it should just work?) | |
//TODO: Accept delimited function names and camelCase them | |
//FUTURE: Do something interesting with this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment