Skip to content

Instantly share code, notes, and snippets.

@meritt
Created November 7, 2012 13:44
Show Gist options
  • Save meritt/4031651 to your computer and use it in GitHub Desktop.
Save meritt/4031651 to your computer and use it in GitHub Desktop.
Нужны ли классы в JavaScript?
function MyCustomType(value) {
this.property = value;
}
MyCustomType.prototype.method = function() {
return this.property;
};
class MyCustomType {
constructor(value) {
this.property = value;
}
method() {
return this.property;
}
}
class Animal {
constructor(name) {
this.name = name;
}
sayName() {
console.log(this.name);
}
}
class Dog extends Animal {
constructor(name) {
super(name);
}
bark() {
console.log('Woof!');
}
}
function Animal(name) {
this.name = name;
}
Animal.prototype.sayName = function() {
console.log(this.name);
};
function Dog(name) {
Animal.call(this, name);
}
Dog.prototype = new Animal(null);
Dog.prototype.bark = function() {
console.log('Woof!');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment