Created
May 7, 2017 22:17
-
-
Save troy-lamerton/4cc49a8e968cf2df1d4eea4362ecaea5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// short-hand functions | |
const pythag = (a, b) => Math.sqrt(a * a + b * b); | |
console.log(pythag(3, 4)); | |
// es6 classes | |
class Dog { | |
constructor(anyType = 'nothing', cute = false) { | |
this.talkThis = anyType; | |
this.cute = cute; | |
this.speak = this.speak.bind(this); | |
} | |
speak(format = true) { | |
const speakString = thing => `woof! I like ${thing}`; | |
if (format) { | |
// new line? no worries | |
console.log(speakString( | |
isNaN(parseInt(this.talkThis, 10)) ? | |
this.talkThis : | |
'numbers') | |
); | |
} else { | |
console.log(speakString(this.talkThis)); | |
} | |
// when your framework doesnt allow if statements | |
!format && console.info('Format was false so we didn\'t format the text'); | |
} | |
} | |
let dogs = [ | |
'food', | |
42, | |
null, | |
'cats' | |
]; | |
new Dog().speak(); | |
dogs.map(value => new Dog(value)).forEach(dog => dog.speak()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment