Javascriptプログラマーは通常 'class'キーワードを使用しません。Javascriptのキーワード 'class'は通常のjavascriptコードには表示されません
私はその理由を知りたいです。要するに
コード以下はそうundetstandやすいと「拡張」を使用して簡単に見えるコンセプト
class Animal {
constructor(type){
this.type = type;
}
static isAnimal(obj, type){
if(!Animal.prototype.isPrototypeOf(obj)){
return false;
}
return type ? obj.type === type : true;
}
}
class Dog extends Animal {
constructor(name, breed){
super("dog");
this.name = name;
this.breed = breed;
}
bark(){
alert("ruff, ruff");
}
print(){
alert("The dog " + this.name + " is a " + this.breed);
}
static isDog(obj){
return Animal.isAnimal(obj, "dog");
}
}
var sparkie = new Dog("Sparkie", "Border Collie");
sparkie.bark();
[ecma6](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes)にはクラス宣言があります。 –
Bhojendra Ndepalは、古いバージョンのjavam(ecam6より古い)がclassキーワードをサポートしていないことを意味しますか? –
ここでは正確に何が問題ですか? – jfriend00