Despite the abundance of questions and resources related to "Javascript: The Good Parts," I am struggling to comprehend a specific sentence in the book. On pages 41-42, the author defines the serial_maker function as follows:
var serial_maker = function ( ) {
// This function produces an object that generates unique strings. Each unique string consists of a prefix
// and a sequence number. The generated object includes
// methods for setting the prefix and sequence
// number, as well as a gensym method for producing unique
// strings.
var prefix = '';
var seq = 0;
return {
set_prefix: function (p) {
prefix = String(p);
},
set_seq: function (s) {
seq = s;
},
gensym: function ( ) {
var result = prefix + seq;
seq += 1;
return result;
}
};
};
var seqer = serial_maker();
seqer.set_prefix('Q');
seqer.set_seq(1000);
var unique = seqer.gensym(); // the value of unique will be "Q1000"
The author further explains:
The methods within this function do not utilize this or that. Consequently, the integrity of the sequer remains intact. It is impossible to access or alter the values of prefix and seq except through approved methods.
I am puzzled about how to use this and/or that to breach this encapsulation. Can someone shed some light on this issue?
Thank you