Skip to content

Instantly share code, notes, and snippets.

@mariyadiminsky
Created June 27, 2016 00:03
Show Gist options
  • Save mariyadiminsky/2c17c0f8a4992c084fe896e7861e83fb to your computer and use it in GitHub Desktop.
Save mariyadiminsky/2c17c0f8a4992c084fe896e7861e83fb to your computer and use it in GitHub Desktop.
// 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