Skip to content

Instantly share code, notes, and snippets.

@lucasdaiki
Last active August 3, 2017 20:23
Show Gist options
  • Save lucasdaiki/76639e8372acba43abf4ddd3988d4e06 to your computer and use it in GitHub Desktop.
Save lucasdaiki/76639e8372acba43abf4ddd3988d4e06 to your computer and use it in GitHub Desktop.
Classes.js
// PROTOTYPE WAY
function Person (props) {
  this.name = props.name
  this.age = props.age
}

Person.prototype.say = function (word) {
  console.log(`${this.name}: ${word}`)
}
// ES6 WAY
class Person {
  constructor({ name, age }) {
    this.name = name
    this.age = age
  }

  say(word) {
    console.log(`${this.name}: ${word}`)
  }
}
var person = new Person({ name: 'Daiki', age: 22 })
person.say('hello!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment