fork download
  1. // "Class" definition and constructor
  2. function foo(value)
  3. {
  4. // Private member
  5. this.value = value;
  6.  
  7. // Private function
  8. this.bar = function() { };
  9.  
  10. return this;
  11. }
  12.  
  13. // Public function
  14. foo.prototype.twice = function() { return this.value + this.value; };
  15.  
  16. var f1 = new foo(1);
  17. var f2 = new foo('1');
  18.  
  19. print(f1.twice());
  20. print(f2.twice());
  21. print(foo(3.14));
  22. print(foo(3.14) instanceof foo);
  23.  
Success #stdin #stdout 0.01s 4984KB
stdin
Standard input is empty
stdout
2
11
[object global]
false