// "Class" definition and constructor
function foo(value)
{
// Private member
this.value = value;
// Private function
this.bar = function() { };
return this;
}
// Public function
foo.prototype.twice = function() { return this.value + this.value; };
var f1 = new foo(1);
var f2 = new foo('1');
print(f1.twice());
print(f2.twice());
print(foo(3.14));
print(foo(3.14) instanceof foo);
Ly8gIkNsYXNzIiBkZWZpbml0aW9uIGFuZCBjb25zdHJ1Y3RvcgpmdW5jdGlvbiBmb28odmFsdWUpCnsKCS8vIFByaXZhdGUgbWVtYmVyCgl0aGlzLnZhbHVlID0gdmFsdWU7CgoJLy8gUHJpdmF0ZSBmdW5jdGlvbgoJdGhpcy5iYXIgPSBmdW5jdGlvbigpIHsgfTsKCglyZXR1cm4gdGhpczsKfQoKLy8gUHVibGljIGZ1bmN0aW9uCmZvby5wcm90b3R5cGUudHdpY2UgPSBmdW5jdGlvbigpIHsgcmV0dXJuIHRoaXMudmFsdWUgKyB0aGlzLnZhbHVlOyB9OwoKdmFyIGYxID0gbmV3IGZvbygxKTsKdmFyIGYyID0gbmV3IGZvbygnMScpOwoKcHJpbnQoZjEudHdpY2UoKSk7CnByaW50KGYyLnR3aWNlKCkpOwpwcmludChmb28oMy4xNCkpOwpwcmludChmb28oMy4xNCkgaW5zdGFuY2VvZiBmb28pOwo=