Javascript Keyword THIS AND ITEM

if( !sky.containers ) sky.containers =
{
        Window : function()
        {
                this.element = document.createElement("div");
                this.element.modal = false; 
                this.element.height = 240;
                this.element.draggable = true;
                this.element.resizable = true;
                this.element.position = "center";
                this.element.width = 240;
                this.element.target = document.body;
                this.element.title ="";
                this.element.headerHeight = 30;;
                this.element.effects = {};
                this.element.show = function()





                return this.element;

        }}

What is the THIS keyword in this context? "sky.containers" or "Window"? And what is ELEMENT if theres no variable does not define this name?

+3
source share
1 answer

Window () is a constructor function. This means that it is called when you create a new object with something like

var myWin = new Window();

Inside the function, it thiswill reference the new object that has just been created. (And which is assigned myWinin the above call example.)

As for "element", this is a property of a newly created object. It does not exist before this line:

this.element = document.createElement("div");

Creates a new <div> element and assigns it a DOM representation of this property.

+4
source

All Articles