Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(){
  2.   'use strict';
  3.  
  4.   // from Prototype.js
  5.   function getArgumentNames(func){
  6.     var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
  7.       .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
  8.       .replace(/\s+/g, '').split(',');
  9.     return names.length === 1 && !names[0] ? [] : names;
  10.   }
  11.  
  12.   var key = 't';
  13.   var mysteriousFunction = function(callback){
  14.     return function(){
  15.       // ident of first-arg or 't'
  16.       key = getArgumentNames(callback)[0] || 't';
  17.       callback(Date.now);
  18.  
  19.       // only once
  20.       mysteriousFunction = function(){
  21.         throw "ERROR: This code runs in your single universe.";
  22.       };
  23.     };
  24.   };
  25.  
  26.   function generateMysteriousObject(){
  27.     var functors = [];
  28.     var mValue;
  29.  
  30.     var mysteriousObject;
  31.     (mysteriousObject = {
  32.       compute:function(functor) {
  33.         return [].push.bind(functors,functor);
  34.       },
  35.       appear:function(value) {
  36.         return function()  {
  37.             mValue = value;
  38.             functors.map( function(functor){ functor(value); } );
  39.         };
  40.       }
  41.     })[key] = function(){
  42.       return mValue;
  43.     };
  44.  
  45.     return mysteriousObject;
  46.   }
  47.  
  48.   var wtf = function(callback)  {
  49.     switch( typeof callback ){
  50.     case "function": return mysteriousFunction(callback);
  51.     default:         return generateMysteriousObject();
  52.   };
  53.  
  54.   Object.defineProperties(wtf, {
  55.     world: {
  56.       set: function(functor) { functor(); }
  57.     }
  58.   });
  59.  
  60.   wtf.log = function()  {
  61.     return console.info.bind(console, arguments);
  62.   };
  63.  
  64.   var root = this;
  65.   if (typeof module !== 'undefined' && module.exports) {
  66.     module.exports = wtf;
  67.   } else {
  68.     root.___ = wtf;
  69.   }
  70.  
  71. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement