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.

Advertisements

2 thoughts on “javascript day – 2

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