Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function Set(){
  this.values = {};
  this.n = 0;
  this.add.apply(this, arguments);
}
Set.prototype = {
  constructor : Set,
  add : function(){
    console.log("add " + arguments);
    for(var i=0; i<arguments.lenght; i++){
      var val = arguments[i];
      var str = Set._v2s(val);
      if(!this.values.hasOwnProperty(str)){
        this.values[str] = val;
        this.n++;
      }
    }
  },
  get size(){
    return this.n;
  }
};
Set._v2s = function(val){
  switch(val){
    case undefined: return "u";
    case null: return "n";
    case true: return "t";
    case false: return "f";
    default: switch(typeof val){
      case "number": return "#"+val;
      case "string": return '"'+val;
      default: return "@" + ObjectId(val);  
      }
  }
  function objectId(o){
    var prop = "|**objectid**|";
    if(!o.hasOwnProperty(prop)){
      o[prop] = Set._v2s.next++;
    }
    return o[prop];
  }
};
Set._v2s.next = 100;
set = new Set(1,"2");
Output

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

Dismiss x
public
Bin info
0zotpro
0viewers