Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- 'use strict';
- // from Prototype.js
- function getArgumentNames(func){
- var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
- .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
- .replace(/\s+/g, '').split(',');
- return names.length === 1 && !names[0] ? [] : names;
- }
- var key = 't';
- var mysteriousFunction = function(callback){
- return function(){
- // ident of first-arg or 't'
- key = getArgumentNames(callback)[0] || 't';
- callback(Date.now);
- // only once
- mysteriousFunction = function(){
- throw "ERROR: This code runs in your single universe.";
- };
- };
- };
- function generateMysteriousObject(){
- var functors = [];
- var mValue;
- var mysteriousObject;
- (mysteriousObject = {
- compute:function(functor) {
- return [].push.bind(functors,functor);
- },
- appear:function(value) {
- return function() {
- mValue = value;
- functors.map( function(functor){ functor(value); } );
- };
- }
- })[key] = function(){
- return mValue;
- };
- return mysteriousObject;
- }
- var wtf = function(callback) {
- switch( typeof callback ){
- case "function": return mysteriousFunction(callback);
- default: return generateMysteriousObject();
- };
- Object.defineProperties(wtf, {
- world: {
- set: function(functor) { functor(); }
- }
- });
- wtf.log = function() {
- return console.info.bind(console, arguments);
- };
- var root = this;
- if (typeof module !== 'undefined' && module.exports) {
- module.exports = wtf;
- } else {
- root.___ = wtf;
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement