class Address
{
constructor(suite, streetAddress, city)
{
[Link] = suite;
[Link] = streetAddress;
[Link] = city;
}
toString()
{
return `Suite ${[Link]}, ` +
`${[Link]}, ${[Link]}`;
}
}
class Employee // renamed
{
constructor(name, address)
{
[Link] = name;
[Link] = address; //!
}
toString()
{
return `${[Link]} works at ${[Link]}`;
}
greet()
{
[Link](
`Hi, my name is ${[Link]}, ` +
`I work at ${[Link]()}` //!
);
}
}
class Serializer
{
constructor(types){
[Link] = types;
}
markRecursive(object)
{
// anoint each object with a type index
let idx = [Link](t => {
return [Link] === [Link];
});
if (idx !== -1)
{
object['typeIndex'] = idx;
for (let key in object)
{
if ([Link](key) && object[key] != null)
[Link](object[key]); // ^^^^^^^^^^ important
}
}
}
reconstructRecursive(object)
{
if ([Link]('typeIndex'))
{
let type = [Link][[Link]];
let obj = new type();
for (let key in object)
{
if ([Link](key) && object[key] != null) {
obj[key] = [Link](object[key]);
}
}
delete [Link];
return obj;
}
return object;
}
clone(object)
{
[Link](object);
let copy = [Link]([Link](object));
return [Link](copy);
}
}
class EmployeeFactory
{
static _newEmployee(proto, name, suite)
{
let copy = [Link](proto);
[Link] = name;
[Link] = suite;
return copy;
}
static newMainOfficeEmployee(name, suite)
{
return this._newEmployee(
[Link], name, suite
);
}
static newAuxOfficeEmployee(name, suite)
{
return this._newEmployee(
[Link], name, suite
);
}
}
[Link] = new Serializer([Employee, Address]);
[Link] = new Employee(null,
new Address(null, '123 East Dr', 'London'));
[Link] = new Employee(null,
new Address(null, '200 London Road', 'Oxford'));
let john = [Link]('John', 4321);
let jane = [Link]('Jane', 222);
[Link]([Link]());
[Link]([Link]());