Skip to content

Instantly share code, notes, and snippets.

@tkd55
Created February 18, 2015 05:18
Show Gist options
  • Save tkd55/6fb1268157ddc0fb3ade to your computer and use it in GitHub Desktop.
Save tkd55/6fb1268157ddc0fb3ade to your computer and use it in GitHub Desktop.
JavaScript ES6

ES5

/*
function Animal(name){
    this.name = name;
}

Animal.prototype.cry = function(voice){
    console.log(voice + 'と鳴きました');
}

function Cat(name){
    Animal.call(this, name);
}

Cat.prototype = Object.create(Animal.prototype);
Cat.prototype.contructor = Cat;

Cat.prototype.meow = function(){
    Animal.prototype.cry.call(this, 'にゃー');
}

var cat = new Cat();
cat.meow();

ES6

class Animal {
    contructor(name){
        this.name = name;
    }

    cry(voice) {
        console.log(this.name + 'は' + voice + 'と鳴きました');
    }
}

class Cat extends Animal {
    contructor(name){
        super(name);
    }

    talk(voice){
        super.cry(voice);
    }
}


var cat = new Cat('タマ');
cat.talk('にゃー');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment