2

I came across this operator preceding a 'this' keyword in some Node.js Harmony code, specifically working with the Koa web framework.

The example code is below:

app.use(function *(){
   var n = ~~this.cookies.get('view') + 1;
   this.cookies.set('view', n);
   this.body = n + ' views';
});

A routine google search showed up nothing so I am throughly confused. The only thing I can say for certain is that it is essential to the functionality of that snippet, as the code stops working when it is removed.

Any insight would be appreciated with identifying the purpose of this alien operator.

1 Answers1

2

It's a double bitwise-NOT. Its only practical effect (as far as I can see) is to cast its argument (all of this.cookies.get('view') in this case) as an integer.

Malvolio
  • 38,966
  • 24
  • 87
  • 125