Created
September 23, 2012 20:55
-
-
Save stickupkid/3773019 to your computer and use it in GitHub Desktop.
Tuple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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