Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Created August 17, 2016 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsharp/223738af901324b81ae18a98b6399cdc to your computer and use it in GitHub Desktop.
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
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