Created
June 27, 2016 00:03
-
-
Save mariyadiminsky/2c17c0f8a4992c084fe896e7861e83fb 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
// Normal function declaration | |
// called before it is declared and it works. | |
callMe(); // Testing, Testing. | |
function callMe() { | |
console.log("Testing, Testing.") | |
} | |
// This is called after, as we would do in a function expression, | |
// and it works too! | |
callMe() // Testing, Testing. | |
// But with classes...You can't create an instance of a class | |
// before creating it: | |
let es6Bunny = new Bunny('Brigadier Fluffkins', 3, 'Raspberry Leaves'); | |
es6Bunny.eatFavFood(); | |
class Bunny { | |
constructor(name, age, favoriteFood){ | |
this.name = name; | |
this.age = age; | |
this.favoriteFood = favoriteFood; | |
} | |
eatFavFood() { | |
console.log(`"Mmmm! Those ${this.favoriteFood} were delicious", said ${this.name} the ${this.age} year old bunny.`); | |
}; | |
} | |
// Instead we get this: Uncaught ReferenceError: Bunny is not defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment