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

I never knew such things like these exists. 😀

Gigaom

Sifteo (see disclosure), the San Francisco-based company known for its popular touchscreen cube games, is launching a second generation of the product that will be available for pre-order on Thursday, expanding to a portable edition that won’t require users to play near a connected laptop.

Currently, Sifteo’s gaming system is composed of Sifteo Cubes, which “are motion-aware 1.7-inch blocks with full-color touch-sensitive TFT LCDs,” the company explains in a press release. “The cubes communicate wirelessly and respond to each others proximity and players’ gestures during gameplay.”

The game system, which was developed by entrepreneurs David Merrill and Jeevan Kalanithi beginning at the MIT Media Lab and later drew attention from the popularity of Merrill’s TED talk, is currently available in a few brick and mortar stores, as well as Amazon and the company’s website. The updated basic package will include three cubes and a base for $129.95, although players can purchase additional cubes and play…

View original post 257 more words

javascript day – 2

javascript – first class citizen, or first class object.

– you can write it anywhere.

// var x = function(){ //anonymous function – created function object on the heap, it is invokable via x.
    // return “Hello”;
// }

// console.log(x));

// var x = function(){ //anonymous function – created function object on the heap, it is invokable via x.
    // return function(){
    // return “Goo”;
    // }
// }

// var a = x();

// console.log(a);

// var rommel = {
    // name: “Rommel”;
    // dept: “Admin”;
// }

// console.log(rommel);

// rommel.name = “Another rommel”;
// rommel[“dept”] = “SWD”;

//when you are creating an object, you are actually creating a new object.

//like a class
function Employee(nameparam, deptparam){

    this.empname = nameparam;
    this.dept = deptparam;
    this.work = function () {
        console.log(this.empname + ” is working “)
        }
    }

}

//this is where the objects are instatiated
var rommel = new Employee(“Rommel”, “Admin”);

console.log(rommel.empname);
console.log(rommel.dept);

rommel.work();
ted.work();
pepper.work();

console.log(Employee.constructor);
console.log(rommel.constructor);

 

function object = hash table.