javascript – 3 & 4

/////////////////day 3

 

object literal {}

object();

function(); – anonymous function

var Car = function() {

    this.engine = {
        shift : function(){
            console.log(“shifting”);       
        }
    }
    this.steering = {
        goLeft : function (){
            console.log(“going left”);
        },
        goRight : function (){
            console.log(“going right”);
        }
    }

}

var toyota = new Car();
toyota.steering.goLeft():
toyota.engine.shift();

 

///////////////////////day 4

function window (){//outermost object
    this.document = new docobject();
}

function docobject(){
    this.forms = new formcollection();
}

function formcollection(){
    this.form1 = new formobject();
    this.form2 = new formobject();
}

function formobject(){
    this.elements = new elementcollection();
    //console.log(“input”);
}

function elementcollection(){
    this.input1 = new input();
}

function input(){
    this.innerhtml = “default inner html”;
    this.click = function(){
    //document.onclick = inner.html;
    console.log(“click”);
    }
}

//
var w = new window();
w.document.forms[“form1”].elements[“input1”].click();
w.document.forms[“form1”].elements[“input1”].innerhtml = “Hi”;
console.log(w.document.forms[“form1”].elements[“input1”].innerhtml);

 

-you have to know how to abstract

-walk thru the code

-spelling / spaces

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s