Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created July 20, 2018 15:18
Show Gist options
  • Save prof3ssorSt3v3/c6175be46efb5f71f44360e13bb474dd to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/c6175be46efb5f71f44360e13bb474dd to your computer and use it in GitHub Desktop.
/****************************
What is a Polyfill
How to create a Polyfill
NOT recommended on DOM Objects
Array - justLetter - only keep
Strings with a specific letter
Date - f$$kinDay - return the day
of the week with prefix
****************************/
let log = console.log;
if(! Array.prototype.sort){
log('sort does not exist');
}
if(! Array.prototype.justLetter ){
//log('justLetter method missing')
Array.prototype.justLetter = function(letter){
let arr = this.filter((item)=>{
if(typeof item != 'string') return false;
return item.indexOf(letter) > -1;
});
return arr;
}
}
let names = ['abc', 'def', {'a':1}, 'cab', 'dac', 123];
log( names );
log( names.justLetter('d') );
if( ! Date.prototype.f$$kinDay ){
//log('f$$kinDay method missing')
Date.prototype.f$$kinDay = function(){
switch(this.getDay()){
case 0:
return 'Today is f$$ckin Sunday';
case 1:
return 'Today is f$$ckin Monday';
case 2:
return 'Today is f$$ckin Tuesday';
case 3:
return 'Today is f$$ckin Wednesday';
case 4:
return 'Today is f$$ckin Thursday';
case 5:
return 'Today is f$$ckin Friday';
case 6:
return 'Today is f$$ckin Saturday';
}
}
}
log( new Date().f$$kinDay() )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment