I have a JavaScript question. Imagine a virtual pen. There are many different possible nibs the pen can have, although the pen can only have one nib. I want to create a pen object and then assign it a nib. The nib needs to access the properties and methods of the pen.
This is probably a well-known design pattern. What is the name of this design pattern?
function Pen() {
var p1=5;
this.nib=null;
}
function Nib1() {
// needs access to p1.
}
function Nib2() {
// needs access to p1.
}
var p = new Pen();
var n1 = new Nib1();
p.nib = n1;
// n1 needs access to p1