co icon indicating copy to clipboard operation
co copied to clipboard

adding ability to pass classical inheritance object

Open teknosains opened this issue 7 years ago • 0 comments

adding ability to pass classical inheritance object

co(function* () {
  function Human(name, age) {
    this.name = name;
    this.age = age;
  }

  Human.prototype.getName = function() {
    return this.name;
  };

  Human.prototype.getAge = function() {
    return this.age;
  }

  let Asian = function(name, age) {
    Human.call(this, name, age);
    this.country = 'Brunei';
  }

  Asian.prototype = Object.create(Human.prototype);

  let agus = new Asian('Agus', 29);

  let res = yield agus;

  console.log(res); // { name: 'Agus', age: 29, country: 'Brunei' }
  console.log(res.getName()); // Agus
  console.log(res.country); // brunei
})
.catch(function(e) {
  console.log(e);
});

teknosains avatar Sep 13 '18 05:09 teknosains