Skip to content

Instantly share code, notes, and snippets.

@demonixis demonixis/Person.dart

Last active Dec 16, 2015
Embed
What would you like to do?
Small comparison between Dart and TypeScript languages to create class with inheritance.
import 'dart:html';
// A base class for a person
class Person {
String name;
String toString() => "Hi ! " + this.name;
Person(String name) {
this.name = name;
}
}
// A class who inherit from Person
class Developer extends Person {
String toString() => super.toString() + " I'm a developer :D";
Developer(String name) : super(name);
}
// Starting point
main() {
var person = new Developer("Yannick");
query('#status').text = person.toString();
}
var Person = (function () {
var person = function (name) {
this.name = name;
};
person.prototype.toString = function () {
return "Hi I'm " + this.name;
};
return person;
})();
var Developer = (function () {
var developer = function (name) {
Person.call(this, name);
};
developer.prototype = new Person();
developer.prototype.toString = function () {
return Person.prototype.toString.call(this) + " I'm a developer :D";
};
return developer;
})();
var developer = new Developer("Yannick");
console.log(developer.toString());
class Person {
private name:string;
constructor(name:string) {
this.name = name;
}
public toString():string {
return "Hi I'm " + this.name;
}
}
class Developer extends Person {
constructor(name:string) {
super(name);
}
toString():string {
return super.toString() + " I'm a developer :D";
}
}
var developer:Developer = new Developer("Yannick");
console.log(developer.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.