Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
const Statuses = Object.freeze({
  UNKNOWN : 0,
  OK      : 1,
  ERROR   : 2,
  STOPPED : 3
});
class myStatus extends Object{
  constructor() {
    super();
    this.status_id = Statuses.UNKNOWN;
  }
  valueOf(){
    return this.status_id;
  }
  getStatus(){
    return this.status_id;
  }
}
var a = new myStatus();
a.status_id = Statuses.ERROR;
console.log(a == Statuses.ERROR);
console.log(a.getStatus() === Statuses.ERROR);
console.log(a.valueOf() === Statuses.ERROR); //Isn't this the same as the line bellow?
console.log(typeof(Statuses.ERROR));
console.log(typeof(a) );
console.log(a.valueOf() === Statuses.ERROR); //Why is this false but the rest are true?
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers