Skip to content

Instantly share code, notes, and snippets.

@oliyoung
Last active June 15, 2017 00:50
Show Gist options
  • Save oliyoung/981d01895104a35a42250f3a987ce7fa to your computer and use it in GitHub Desktop.
Save oliyoung/981d01895104a35a42250f3a987ce7fa to your computer and use it in GitHub Desktop.
const data = { name: 'Apple', type: 'Fruit', color: 'red' }
class Fruit {
constructor(data) {
this.data = data
}
isRed() {
this.color === 'red';
}
}
const apple = new Fruit(data);
assert(apple.isRed());
assert(apple.name, 'Apple');
@sophistifunk
Copy link

const inputData = { name: 'Apple', type: 'Fruit', color: 'red' } 

class Fruit {
  constructor(data) {
    const { name, type, color } = data;
    this.name = name;
    this.type = type;
    this.color = color;
  }
  
  isRed() {
    return this.color === 'red';
  }
  
}

(function() {
  let apple = new Fruit(inputData);
  
  function assert(left, right) {
    if (left !== right) {
      console.error("expected", left, "to be", right);
    }
  }
  
  console.log(apple)
  
  assert(apple.isRed(), true);
  assert(apple.name, 'Apple');
})()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment