I understand the word self has no special meaning in javascript. Below code, while if one writes as var Life = function( ....), it's clear but author decide to do var _ = self.Life = function(...). While I understand the var _ part(so that internally, it can refer to samething by shorter name), I don't get self.Life (instead of Life).. Can someone please explain this?
(function() {
var _ = self.Life = function(seed) {
this.seed = seed;
this.height = seed.length;
this.width = seed[0].length;
this.prevBoard = [];
this.board = cloneArray(seed);
};
_.prototype = {
next: function() {
//
},
toString: function() {
return this.board.map(function(row) {
return row.join(' ');
}).join('\n');
}
};
function cloneArray(array) {
return array.slice().map(function(row) {
return row.slice();
});
}
})();
undefined
var game = new Life([
[0, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 1]
]);
undefined
console.log(game + ' ');