Skip to content

Instantly share code, notes, and snippets.

@LayneSmith
Created May 3, 2017 19:47
Show Gist options
  • Select an option

  • Save LayneSmith/6a890f6ddaece1ee798214c404a7f530 to your computer and use it in GitHub Desktop.

Select an option

Save LayneSmith/6a890f6ddaece1ee798214c404a7f530 to your computer and use it in GitHub Desktop.
Holding for inheritance work
// function Dog(name, breed) {
// this.name = name;
// this.breed = breed;
// }
//
// Dog.prototype.bark = function () {
// console.log(`Bark Bark! My name is ${this.name}`);
// };
// Dog.prototype.cuddle = function () {
// console.log('I love you, owner!');
// };
//
// const princess = new Dog('Princess', 'King Charles');
// const snickers = new Dog('Snickers', 'King Charles');
class Dog {
// REQUIRED MINIMUM
// construct properties and methods all pieces get
constructor(name, breed) {
this.name = name;
this.breed = breed;
} // No commas
bark() { // pass in variables if necessary
console.log(`Bark Bark! My name is ${this.name}`);
}
cuddle() { // pass in variables if necessary
console.log('I love you, owner!');
}
// STATIC INFO
static info() { // Static method attached only to Dog class, not sure of usefulness.
console.log('Dogs are better than cats by a factor of 10!');
// Dog.info() NOT princess.info
}
// GETTERS AND SETTERS
get description() { // A computed property
return `${this.name} is a ${this.breed} type of dog.`;
// princess.description returns 'Princess is a King Charles type of dog.'
}
set nicknames(value) { // INPUT: sets nicknames property to post-processed value
this.nick = value.trim();
}
get nicknames() { // A computed property that was set above but we still do stuff to it.
return this.nick.toUpperCase();
}
}
const princess = new Dog('Princess', 'King Charles');
const snickers = new Dog('Snickers', 'King Charles');
class Animal {
constructor(name){
this.name = name;
this.thirst = 100;
this.belly = [];
}
drink() {
this.thirst -= 10;
return this.thirst;
}
eat(food) {
this.belly.push(food);
return this.belly;
}
}
// Extend animals with specifics about Dog
class Dog2 extends Animal {
constructor(name, breed) {
super(name); // Create Animal class first, required. Can pass through variables
this.breed = breed;
}
bark() {
console.log('Bark bark, I\'m a dog');
}
}
const rhino = new Animal('Rhiney');
const bj = new Dog2('BJ', 'German Shepherd');
$(document).ready(() => {
// const quoteInfo = `
// <h3>{{name}}</h3>
// <ol>
// {% for quote in quotes%}
// <li>
// {{quote}}
// </li>
// {%endfor%}
// </ol>
// `;
// console.log(quoteInfo);
// const nttTemplate = nunjucks.compile(quoteInfo);
// nttTemplate.render({
// name: 'Yogi Berra',
// quotes: [
// { quote: 'I said this' },
// { quote: 'I said that' },
// { quote: 'I said the other' },
// ],
// });
// $('.oop').append(nttTemplate);
// const ntt = '<h1>{{name}}\'s NTT</h1>';
// const template = Handlebars.compile(ntt);
// const data = template({name:'Layne'});
// $('.oop').append(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment