We define our own Object (or 'class'), in a 'constructor function', called 'City',...

with some 'properties',...

and one 'method',...

called 'add'.

'this' refers to (or will refer to) the instance at hand, in this case, the city being worked on.

'ct1' and 'ct2' are initially set to 'null', to indicate 'not referring to any specific object yet'.

With 'new' a City instance can be created,...

where the arguments are then copied to the instance's properties.

Same for 'ct2', that then has its own, different, property values.

Two different instances, both based on the same model, City.

When City's method 'add' is called, it is called on ct2...

with the user's input as argument,...

so ct2's property 'nr_residents' (only ct2's) is changed. 'this' is now equivalent to 'ct2'.

ct2's property's value is saved beforehand.

========

Now this would be something to stuff in a file, say, 'ourobjects.js', so it can be linked to from any document, by setting a 'src' attribute in a 'script' tag. That means that you can use 'City' and other custom Objects anywhere.

========

An initially invisible error message,...

shown when necessary.

========

'with' can sometimes come in handy, to deal with one specific instance.