Published
Edited
Jan 21, 2020
Insert cell
md`# Messing with Classes`
Insert cell
Person1 = {
let Foo = function(name, age) {
this.name = name;
this.age = age;
this.hasBirthday = function() { this.age++; };
}
Foo.prototype = {
getName: function() { return this.name; }
}
return Foo;
}
Insert cell
Person2 = {
return class {
constructor(name, age) {
this.name = name;
this.age = age;
this.hasBirthday = function() { this.age++; };
}
getName() {
return this.name;
}
}
}
Insert cell
jim = new Person1('Jim', 39);
Insert cell
bob = new Person2('Bob', 21);
Insert cell
jim.age;
Insert cell
jim.getName();
Insert cell
bob.age;
Insert cell
bob.getName();
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more