Platform
Resources
Pricing
Sign in
Get started
James Saunders
Lead maintainer of of d3-x3d.
Workspace
Fork
Published
By
James Saunders
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.
Try it for free
Learn more
Fork
View
Export
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Person1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Person2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
jim
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
bob
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML