Created
November 7, 2012 13:44
-
-
Save meritt/4031651 to your computer and use it in GitHub Desktop.
Нужны ли классы в JavaScript?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MyCustomType(value) { | |
this.property = value; | |
} | |
MyCustomType.prototype.method = function() { | |
return this.property; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyCustomType { | |
constructor(value) { | |
this.property = value; | |
} | |
method() { | |
return this.property; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal { | |
constructor(name) { | |
this.name = name; | |
} | |
sayName() { | |
console.log(this.name); | |
} | |
} | |
class Dog extends Animal { | |
constructor(name) { | |
super(name); | |
} | |
bark() { | |
console.log('Woof!'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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