HotelCalifornia.js

<Krishean> function echo(a){return WScript.Echo(a);}
<Krishean> function exit(a){return WScript.Quit(a);}
<Krishean> exit(main());
<Krishean> function main(){
<Krishean> 
<Krishean>  var h=new hotel();
<Krishean>  h.name='california';
<Krishean>  h.guest.addEvent('checkout');
<Krishean>  h.guest.removeEvent('leave');
<Krishean> 
<Krishean>  echo(print_r(h));
<Krishean> 
<Krishean>  return 0;
<Krishean> }
<Krishean> function hotel(){
<Krishean>  this.name='';
<Krishean>  this.guest={
<Krishean>   'events': ['leave'],
<Krishean>   'addEvent': function(a){
<Krishean>    this.events.push(a);
<Krishean>    return;
<Krishean>   },
<Krishean>   'removeEvent': function(a){
<Krishean>    if(Array_indexOf(this.events,a)!=-1){
<Krishean>     Array_remove(this.events,a);
<Krishean>    }
<Krishean>    return;
<Krishean>   }
<Krishean>  };
<Krishean> }
<Krishean>  // Array_indexOf( array, value, begin, strict ) - Return index of the first element that matches value
<Krishean> function Array_indexOf(a,v,b,s){for(var i=+b||0,l=a.length;i<l;i++)if(a[i]===v||s&&a[i]==v)return i;return -1;}
<Krishean>  // Array_remove( array, value ) - Remove all array elements that match value
<Krishean> function Array_remove(a,v){for(var i=0;i<a.length;i++){if(a[i]==v){a.splice(i,1);i--;}}return a;}
<Krishean> function print_r(arr,lvl){ // debugging, print out variables
<Krishean>  var out='';
<Krishean>  if(!lvl)lvl=0;
<Krishean>  var pad='';
<Krishean>  if(lvl)for(var i=0;i<lvl+1;i++)pad+='    ';
<Krishean>  if(typeof(arr)=='object'){
<Krishean>   var typ=new String(arr.constructor);
<Krishean>   out+=typ.substring(typ.indexOf(' ')+1,typ.indexOf('('))+"\n"+pad+"(\n";
<Krishean>   for(var i in arr)out+=((typeof(arr[i])=='object')?(pad+'    ['+i+'] => '+print_r(arr[i],lvl+1)+"\n"):(pad+'    ['+i+'] => "'+arr[i]+"\"\n"));
<Krishean>   out+=pad+')';
<Krishean>  }else{
<Krishean>   var typ=new String(arr.constructor);
<Krishean>   out='===>'+arr+'<===('+typ.substring(typ.indexOf(' ')+1,typ.indexOf('('))+')';
<Krishean>  }
<Krishean>  return out;
<Krishean> }
<Krishean>  // done
<Krishean> you can actually run that

0 comments: