The New Keyword

playing with the new keyword

by Terrance Smith

JavaScript

//iterates through each member of an object
var showMemberInfo = function (obj) {
    if (!obj) {
        console.info("info is undefined");
    } else {
        for (var i in obj) {
            //member of type exist
            console.info(i + " = " + obj[i]);
        }
    }
};
//my type
var myGlobalType = function () {
    var self = this;
    self.name = "Joe";
    self.val = 12;
};

//instance of my type
var myInstance = new myGlobalType();
console.info(" --------------------my instance Insides --------------------\r\n");
console.info("my instance = " + myInstance);
console.info("my instance.prototype = " + myInstance.prototype);
console.info("my instance constructor = " + myInstance.constructor);
console.info("my instance show Member info called ");
showMemberInfo(myInstance);
console.info("my instance show Member info called on prototype");
showMemberInfo(myInstance.prototype);

console.info(" --------------------my Global Type Insides -------------------- \r\n");
console.info("my Global Type = " + myGlobalType);
console.info("my Global Type prototype = " + myGlobalType.prototype);
console.info("my Global Type constructor = " + myGlobalType.constructor);
console.info("my Global Type show Member info called ");
showMemberInfo(myGlobalType);
console.info("my Global Type show Member info called on prototype");
showMemberInfo(myGlobalType.prototype);