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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more