Skip to content

Instantly share code, notes, and snippets.

@stickupkid
Created September 23, 2012 20:55
Show Gist options
  • Save stickupkid/3773019 to your computer and use it in GitHub Desktop.
Save stickupkid/3773019 to your computer and use it in GitHub Desktop.
Tuple
function Tuple(_1) {
this.__1 = _1;
}
Tuple.prototype = {
toString: function() {
return "Tuple";
}
};
function tuple1(value) {
var tuple = Object.create(new Tuple(value));
Object.defineProperty(tuple, "_1", {
get: function() {
return this.__1;
},
configurable: false
});
Object.freeze(tuple);
return tuple;
}
function log(value){
if(arguments.length) {
console.log(value);
} else {
console.log(Array.prototype.slice.call(arguments).join(", "));
}
}
var tuple = tuple1(1.23);
log(tuple);
log(tuple._1);
log(tuple instanceof Tuple);
log(Tuple.prototype.isPrototypeOf(tuple));​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment