July 10, 2008

Window Object in Javascript

Nikolai Kordulla

0 comments >>

The window object which you can use in javascript is one of the unestimated things in javascript. You can have access on every function, object with the window object. To call an alert you can use window['alert']('hello').

I personally use the window object often for callback functions like you can see in this simple example:
<script type="text/javascript">
function Show()
{
   this.randomString = 'sdsdsifiifg11fdf';
   window[this.randomString] = this;

   this.doAction = function()
   {
      var call = new Callback();
      call.makeCallback(this.randomString, 'doCallback');
   }

   this.doCallback = function()
   {
      alert('Called');
   }
}

function Callback()
{
   this.makeCallback = function(obj, func)
   {
      window[obj][func]();
   }
}

var test = new Show();
test.doAction();
</script>

Comments

 

Leave a Reply

Don't enter anything here:
Name (required) Invalid name
Mail (will not be published) (required) Invalid mail
Website Invalid url

Content couldnt be empty.