FANDOM


This entry is intended to show how I use a simple text file as a working console for snippet testing.

It is rough still. I intend to clean it up and flesh out explanations...

SourceEdit

the most useful library around:

<script src="http://localhost/js/jquery.js"></script>

SetupEdit

some basic defaults:

  1. put every thing into a try block
<script>
try{ var u=undefined, br='<hr>';
  function long(x){log(x,1)}
  function log(x,y){document.write((y?br:'  //  ')+x)}

exampleEdit

Bunch of random test code

  /* NOTES
  mollypages.org/misc/jsclo.mp
  
  
  
  function Delegater(args){
    var cache={}, Delegate = function(){};
    with (Delegate) {
      prototype.get=function(np){return cache[np]}
      prototype.set=function(n,v){cache[n]=v}
      prototype.toString=function(){return '[instance Delegate]'}                 
    } return new Delegate();
  };
  del = Delegater(); long(del);
  del.set('a',3); del.a=9;
  long(del.a); log(del.get('a'));
  
  
  
  
  function callLater(paramA, paramB, paramC){
      return (function(){$('#'+paramA)[0].style[paramB]=paramC});
  }
  var functRef = callLater("e1", "display", "none");
  hideMenu=setTimeout(functRef, 500);
  
  
  function Container(param) { param = param || 'param';
    var that = this; this.c = 'Cc';
    this.pubInstVar = (param || 3);
    this.pubMethod = function (string) {
      return privMethod (string)
    }
    var privInstVar = param;
    var privMethod = function (string) { string = string || 'string';
      return privInstVar+' '+string;
    }
  }
  
  var C = new Container(4);
  log(C.pubMethod(8))
  
  function say667(){var num=666,f=function(){log(num)};num++;return f}
  var sn = say667(); log(sn);
  
  function setupSomeGlobals() {
    // Local variable that ends up within closure
    var num = 666;
    // Store some references to functions as global variables
    gAlertNumber = function() { log(num); }
    gIncreaseNumber = function() { num++; }
    gSetNumber = function(x) { num = x; }
  }
  
  
  setupSomeGlobals();
  
  
  function newClosure(someNum, someRef) {
    var num = someNum;
    var arr = [1,2,3];
    var ref = someRef;
    return function(x) {
        num += x;
        arr.push(num);
        long('Init: ' + num);
        log('Array: ' + arr);
        log('ref.someVar ' + ref.someVar);
      }
  }
   
  closure1 = newClosure(40, {someVar : 'closure 1'});
  closure2 = newClosure(1000, {someVar : 'closure 2'});
  
  
    closure1(5);
    closure2(-10);
  */
  
  
  
  var myObject = function() {
    var priVar = 'This variable is private!';
    var priFun = function() {
      long('This function is private!');
    }
    return {
      showPri : 
        function() { long(priVar); return this },
      callPri :
        function() { priFun(); return this },
      chanPri :
        function(s){ priVar = s; return this },
      valueOf :
        function() { return priVar }
    }
  }();
  
  long(myObject.showPri().callPri().chanPri(9))
  

  

endEdit

  1. log a dot to signify an end
  2. tweak background color as indication of all source loaded
  long('.');$(function(){$('body').css('background','#eff')})
  } catch(err){log(br+' . . . '+err)}
</script>
  
  <div id="e1">e1</div>

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.