103
rated 0 times
[
108]
[
5]
/ answers: 1 / hits: 5863
/ 10 Years ago, wed, march 5, 2014, 12:00:00
What is the usage of the construct: function F() { if (!(this instanceof F)) { return new F() }; ... }
?
I found this in a pty.js
for Node. Here is the original code:
function Terminal(file, args, opt) {
if (!(this instanceof Terminal)) {
return new Terminal(file, args, opt);
}
var self = this
, env
, cwd
, name
, cols
, rows
, term;
-------------------SKIP-----------------------------------
Terminal.total++;
this.socket.on('close', function() {
Terminal.total--;
self._close();
self.emit('exit', null);
});
env = null;
}
More From » javascript